0

我正在使用以下内容来获取手机的位置..

  <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。它确实要求允许跟踪该位置。它确实返回本地区域周围的随机位置。

为什么是这样?

4

3 回答 3

1

简单的回答,没有回答,所有手机都以不同的方式对待这个问题。我发现强制gps的唯一方法是在本机应用程序中

于 2013-05-03T22:21:56.277 回答
0

这取决于设备。您会发现许多设备实际上确实返回了正确的位置。

您可能会注意到,当 GPS 初始化时,它并没有从卫星上得到很好的修复,而是为您提供最后已知的位置、基于网络数据的位置或基于有限卫星数据的位置。

也可以将某些设备配置为仅共享一个“粗略”的位置,这并不像它可能的那样具体或准确。

于 2012-11-24T09:22:51.840 回答
0

大多数智能手机都有不止一种定位方式,例如用于高精度(精细)定位的 GPS 和用于低精度(粗略)定位的蜂窝塔定位。在您的成功函数中返回的位置上,您应该得到一个准确度的估计值coords.accuracy

进行位置查询时,您可以通过指定请求高精度响应enableHighAccuracy = true

 navigator.geolocation.getCurrentPosition(geo_success, geo_error,
       {enableHighAccuracy = true});

请注意,这可能并不总是有效,因为某些设备不允许您访问高精度定位(出于多种考虑,其中之一是 GPS 定位会影响电池使用)。

于 2012-11-24T09:24:58.433 回答