Reputation: 75
I am using the javascript googlemap API. I want the user to define a city name. Then I store the name + coordinate in a database.
It is easy to do, but the problems are :
So can I know the name of the city under one specific coordinates ? Idem for country ? Can I know if there is no city or country under it ? Do you have other ideas for my problems ?
Thanks!
Upvotes: 4
Views: 4221
Reputation: 30180
You do not need reverse geocoding.
Use Google's geocoder to get the lat/lng of the city. Google will return the name of the city it found in its response:
Here's a geocoding request with Paris spelled incorrectly: http://maps.googleapis.com/maps/api/geocode/json?address=Paaris&sensor=false
Google gives you the correct place in the response...
{
"status": "OK",
"results": [ {
"types": [ "locality", "political" ],
"formatted_address": "Paris, France",
"address_components": [ {
"long_name": "Paris",
"short_name": "Paris",
"types": [ "locality", "political" ]
}, {
"long_name": "Paris",
"short_name": "75",
"types": [ "administrative_area_level_2", "political" ]
}, {
SO...
As a intermediate step you could also check if the entered city is different than the city google found and verify with the user.
Upvotes: 3
Reputation: 3897
I think reverse geocoding is what you are looking for. You will find details of obtaining the country, city and other location details by passing the co-ordinates here.
Upvotes: 3
Reputation: 78751
Maybe this can help you:
http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
Upvotes: 3