简体   繁体   English

在Phonegap(Cordova 2.9.0)iOS上进行地理位置定位

[英]geolocation on Phonegap (Cordova 2.9.0) iOS

I'm using Cordova 2.9.0 and Xcode 5.0 我正在使用Cordova 2.9.0和Xcode 5.0

I'm trying to do this tutorial: http://docs.phonegap.com/en/2.4.0/cordova_geolocation_geolocation.md.html 我正在尝试执行本教程: http : //docs.phonegap.com/en/2.4.0/cordova_geolocation_geolocation.md.html

I copied the code from the geolocation.getCurrentPosition and there the "Full Example" (with html and javascript-code) 我从geolocation.getCurrentPosition复制了代码,然后找到“完整示例”(带有html和javascript代码)

I checked my config.xml and it has 我检查了我的config.xml,它有

<feature name="Geolocation">
  <param name="ios-package" value="CDVLocation"/>
</feature>

All I'm getting in the iPhone-Simulator is: "Finding geolocation..." But I waited for like 5mins and nothing happened - not getting any geolocation-data. 我在iPhone模拟器中获得的所有信息是:“查找地理位置...”,但我等了5分钟,却什么都没发生-没有获得任何地理位置数据。

I hope someone could help me 我希望有人可以帮助我

You can try a few things, or post more details if these fail to resolve it: 您可以尝试一些操作,或者在无法解决问题时发布更多详细信息:

  • Your link points to the Cordova docs for version 2.4 and you are using 2.9, so although the spec for geolocation has not changed much, better to use the docs for that version. 您的链接指向版本2.4的Cordova文档,而您使用的是2.9,因此尽管地理位置规范没有太大变化,但最好使用该版本的文档。

  • Check that you are including the cordova.js file. 检查您是否包含cordova.js文件。 In the example in the docs the js file is named "cordova-xxxjs", you of course need to substitute that for the correct file name for your project/version. 在文档的示例中,js文件名为“ cordova-xxxjs”,您当然需要用它替换项目/版本的正确文件名。

  • On the iPhone emulator (not the best way to check geolocation really) check that you have a mock location setup: Go to Debug > Location and select a predefined location or a custom one. 在iPhone模拟器上(不是真正检查地理位置的最佳方法),请检查您是否具有模拟位置设置:转到“调试”>“位置”,然后选择预定义的位置或自定义位置。

  • Add console.log() calls or alert() to check whether the listener is being executed at all and to check for the presence of the plugin, like: 添加console.log()调用或alert()来检查侦听器是否正在执行,并检查是否存在插件,例如:

    function onDeviceReady() { 函数onDeviceReady(){
    alert("on device ready listener executed"); alert(“在设备就绪的监听器上执行”);
    alert(navigator.geolocation); 警报(navigator.geolocation);
    navigator.geolocation.getCurrentPosition(onSuccess, onError); navigator.geolocation.getCurrentPosition(onSuccess,onError);
    } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM