I'm using javascript function to get user latitude and longitude using google map api.
$(document).ready(function () {
navigator.geolocation.getCurrentPosition(function (pos) {
var lat = pos.coord开发者_StackOverflow社区s.latitude;
var lon = pos.coords.longitude;
});
});
does any one know how to get location name instead of latitude and longitude? for example Beverly Hills, California
Use the Google Maps API's Geocoding service. You can pass in the latlng
to the geocode request, and in the callback expect the data of the address.
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': currentLocation }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//the `results` variable will be an array with formatted addresses and location details
}
});
精彩评论