Issue
Is is possible to show a map-view in android an allow the user to select an area for example a country or state ?
Clarification :
I want to let users select a country from the map view , How is that possible ?
I don't care about whether the selected country is highlighted or not , I only care about retrieving which country was selected / touched/ marked by the user
Solution
There's a method to get lat, lon from map how to get lat and long on touch event from google map?
After that you can call Google Geo Code API to convert this lat,lon to physical address,
i.e.
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false
The Above link will return JSON
{
"status": "OK",
"results": [ {
"types": street_address,
"formatted_address": "275-291 Bedford Ave, Brooklyn, NY 11211, USA",
"address_components": [ {
"long_name": "275-291",
"short_name": "275-291",
"types": street_number
}, {
"long_name": "Bedford Ave",
"short_name": "Bedford Ave",
"types": route
}, {
"long_name": "New York",
"short_name": "New York",
"types": [ "locality", "political" ]
}, {
"long_name": "Brooklyn",
"short_name": "Brooklyn",
"types": [ "administrative_area_level_3", "political" ]
}, {
"long_name": "Kings",
"short_name": "Kings",
"types": [ "administrative_area_level_2", "political" ]
}, {
"long_name": "New York",
"short_name": "NY",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "United States",
"short_name": "US",
"types": [ "country", "political" ]
}, {
"long_name": "11211",
"short_name": "11211",
"types": postal_code
} ],
"geometry": {
"location": {
"lat": 40.7142298,
"lng": -73.9614669
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"southwest": {
"lat": 40.7110822,
"lng": -73.9646145
},
"northeast": {
"lat": 40.7173774,
"lng": -73.9583193
}
}
}
},
... Additional results[] ...
Now you can parse JSON and get country name city name locality, state etc etc.
Or other option is to get just country code.
http://ws.geonames.org/countryCode?lat=25.03&lng=67.2
this will return country code PK = Pakistan you can either get the country code list, or
Answered By - Adeel Pervaiz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.