【问题标题】:Phonegap not detecting accurate locationPhonegap 未检测到准确位置
【发布时间】:2013-04-24 06:27:12
【问题描述】:

我在 phonegap 中使用 HTML5 Geolocation API 来精确检测我的位置。我在印度工作,理想情况下,我应该能够看到我的位置,即印度浦那,但事实并非如此。

它将“美国加利福尼亚州旧金山”检测为我的位置。可能是什么问题?

谢谢大家。非常感谢您的帮助。

让我分享代码:)

document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
    // onSuccess Callback
    //   This method accepts a `Position` object, which contains
    //   the current GPS coordinates
    //

    var onSuccess = function(position) {
        var lattitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        //Ajax Call
        $.ajax({
               url: 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+lattitude+','+longitude+'&sensor=true',
               success: function(data){
                alert(data.results[0].formatted_address);
               //alert(data.results[1].formatted_address);
               },
               error: function(data){
               alert('error');
               }
               });//Ajax call ends
    };

    function onError(error) {
        alert('code: '+ error.code + '\n' + 'message: ' + error.message + '\n');
    }

    navigator.geolocation.getCurrentPosition(onSuccess, onError);
}

【问题讨论】:

  • 你是从模拟器得到这个吗?如果是这样,那是您的问题 - 模拟器的静态位置设置为 SF。
  • 另外,仅供参考,地理位置不是 HTML5 的一部分。

标签: html cordova geolocation


【解决方案1】:

如果您使用的是 iOS 模拟器,您将始终将 SF 作为位置,因为它具有静态位置设置。但是,您可以使用这个漂亮的工具在浏览器中进行模拟,它会让您弄乱位置设置等等。

http://emulate.phonegap.com/

【讨论】:

  • 谢谢德鲁。让我试一试。
  • @VinodSobale 应该可以帮到你 - 不知道你为什么被否决 - 这是一个很好的问题,在其他地方没有涉及很多。
  • @Drew Dahlman 哦..是的。我想这将是一个非常具体的问题。反正。谢谢你。
  • @Drew Dahlman 也许,因为我提到我在印度做这个
猜你喜欢
  • 2017-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-26
  • 2015-12-13
  • 1970-01-01
相关资源
最近更新 更多