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!
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.
Maybe this can help you:
http://code.google.com/apis/maps/documentation/geocoding/#ReverseGeocoding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With