A little js code to retrieve long and lat from adress using google api
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function getLtLgFromAdresse(address,apiKey){ var lng; var lt; jQuery.ajax({ type: "GET" , dataType: "xml" , success: function (xml) { if (jQuery(xml).find( 'status' ).text() == 'OK' ){ var locationNode = jQuery(xml).find( 'result:first' ). find( 'geometry' ).find( 'location' ); lng = locationNode.find( 'lng' ).text(); lt = locationNode.find( 'lat' ).text(); alert( "lng: " +lng+ " lat:" +lt) } else { alert( 'Error!' ); } } }); } |
https://developers.google.com/maps/documentation/geocoding/
Note that here we show only the first occurence "using the :first near to the selector result.
No comments:
Post a Comment