Created
March 11, 2014 18:35
-
-
Save ricardodantas/9492153 to your computer and use it in GitHub Desktop.
Google Maps API - Pegar a latitude e longitude de um endereço
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.geocoder = new google.maps.ClientGeocoder(); | |
geocoder.getLocations('rua xyz, sp', function(result){ | |
var placemark = result.Placemark[0]; // Only use first result | |
var accuracy = placemark.AddressDetails.Accuracy; | |
var zoomLevel = 1; | |
var lon = placemark.Point.coordinates[0]; | |
var lat = placemark.Point.coordinates[1]; | |
gmap.setCenter(new google.maps.LatLng(lat, lon), zoomLevel); | |
}); | |
//----------------------- | |
// ou | |
//----------------------- | |
// Apenas retorna latitude e longitude | |
function GetLocation(address) { | |
var geocoder = new google.maps.Geocoder(); | |
geocoder.geocode({ 'address': address }, function (results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
var latitude = results[0].geometry.location.lat(); | |
var longitude = results[0].geometry.location.lng(); | |
alert("Latitude: " + latitude + "\nLongitude: " + longitude); | |
} else { | |
alert("Request failed.") | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment