Google Maps: How to get Latitude and Longitude from an address
Wednesday, May 14, 2008 Also this time I reply to a comment with a post, given the general interest. Armando asked me if it was possible, via Google Maps, get Latitude and Longitude from a city name or street. The answer is yes! Using the Google Maps API geocoding service can be requested directly to Google from reprocessing our textual information (state, city, street) in geographic coordinates. You can try a sample online directly on the site of documementazione Google.
The main object that allows this is GClientGeocoder Using the method getLatLng() you can convert a string address into an object GLatLng
NOTE: remember to include the need to take a free Google API key: See How to put Google Map into their Web about how to obtain the API key. This will be used for the inclusion of the script, in the form:
- "http://www.google.com/jsapi?key=ABCDEFG" type = "text/javascript" >< / script> <script "http://www.google.com/jsapi?key=ABCDEFG" src = type = "text/javascript"> </ script>
Where is 'ABCDEFG', should be replaced with the key that Google releases free: Get key Google.
The use of this object is really easy, as most of the API provided by Google:
- / / Create the object GClientGeocoder
- new GClientGeocoder ( ) ; var geocoder = new GClientGeocoder ();
- / / The address is just a text, could be just a city
- 'via salaria, roma, italia' ; var address = 'Via Salaria, Rome, Italy';
- address , geocoder. getLatLng (address,
- point ) { function (point) (
- ! point ) { if (point) (
- address + ' non trovato' ) ; alert (address + 'not found');
- { ) Else (
- 'Latitudine = ' + point. lat ( ) + ' Longitudine = ' + point. lng ( ) ) ; alert ( 'Latitude =' + point. lat () + 'Longitude =' + point. lng ());
- )
- )
- )
For completeness, also shows how to perform the reverse procedure, at this point. By adding an event to our map, it is possible to know which are the values of Latitude and Longitude:
- map , "click" , GEvent. AddListener (map, "click",
- overlay , point ) { function (overlay, point) (
- "Latitudine = " + point. lat ( ) + " Longitudine = " + point. lng ( ) ; myHTML var = "Latitude =" + point. lat () + "Longitude =" + point. lng ();
- point , myHtml ) ; map. openInfoWindow (point, myHTML);
- )
- )














[...] Track from [...]
Excellent thanks!
goods!
pour ceux qui développe en local, vous pouvez utiliser http://localhost cle pour la demande de google
thanks for the help.
Even more simple and fully automatic:
http://mygeoposition.com
Thanks I was looking for exactly