通过谷歌地图地理定位,我在这里获取了纬度、经度,包括用户所在位置的准确位置。
https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=false
"
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success);
} else {
alert("Geo Location is not supported on your current browser!");
}
function success(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
var myLatlng = new google.maps.LatLng(lat, long);
var geocoder, add, country;
geocoder = new google.maps.Geocoder();
geocoder.geocode({
'latLng': myLatlng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
add = results[1].formatted_address;
country = results[9].formatted_address;
}
}
});
}