How retrieve latitude and longitude via Google Maps API?
Reminder: To use the Geocoding API, you must enable billing on each of your projects and include an API key with all API or SDK requests. The Geocoding API uses a pay-as-you-go pricing model.
With API v3
google.maps.event.addListener(map, 'click', function(event) {
alert( 'Lat: ' + event.latLng.lat() + ' and Longitude is: ' + event.latLng.lng() );
});
Likewise you can retrieve when a marker is dragged dropped :
google.maps.event.addListener(marker, 'dragstart', function(event) {
alert( 'Lat: ' + event.latLng.lat() + ' and Longitude is: ' + event.latLng.lng() );
});
If you need to find out the latitude and longitude of an address using the Google Maps API, you need to use the Google Maps Geocoding Service:
var map = new GMap2(document.getElementById("map_canvas"));
var geocoder = new GClientGeocoder();
var address = "1600 Amphitheatre Parkway, Mountain View";
geocoder.getLatLng(address, function(point) {
var latitude = point.y;
var longitude = point.x;
// do something with the lat lng
});
If you would like to get the latitude and longitude of a position clicked on your Google map, you can do this in the click event:
GEvent.addListener(map, "click", function(marker,point) {
var latitude = point.y;
var longitude = point.x;
// do something with the lat/lng
});
I have found the result via the following method:
http://maps.googleapis.com/maps/api/geocode/json?address=woking&sensor=false
console.log(response.results[0].geometry.viewport.northeast.lat);
console.log(response.results[0].geometry.viewport.northeast.lng);
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