我正在使用以下内容来获取手机的位置..
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" >
$(document).ready(function () {
// wire up button click
$('#go').click(function () {
// test for presence of geolocation
if (navigator && navigator.geolocation) {
// make the request for the user's position
navigator.geolocation.getCurrentPosition(geo_success, geo_error);
}
});
});
function geo_success(position) {
printAddress(position.coords.latitude, position.coords.longitude);
alert(position.coords.latitude + " " + position.coords.longitude)
}
// use Google Maps API to reverse geocode our location
function printAddress(latitude, longitude) {
// set up the Geocoder object
var geocoder = new google.maps.Geocoder();
// turn coordinates into an object
var yourLocation = new google.maps.LatLng(latitude, longitude);
// find out info about our location
geocoder.geocode({ 'latLng': yourLocation }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
$('body').append('<p>Your Address:<br />' +
results[0].formatted_address + '</p>');
} else {
error('Google did not return any results.');
}
} else {
error("Reverse Geocoding failed due to: " + status);
}
});
}
}
结果永远不会来自手机 GPS。它确实要求允许跟踪该位置。它确实返回本地区域周围的随机位置。
为什么是这样?