【发布时间】:2015-11-08 13:07:12
【问题描述】:
我搜索了与基于地理位置的警报问题相关的各种论坛和帖子;出于某种原因,在我的情况下没有任何技术起作用。
在我的 Ionic 框架项目中添加了“cordova-plugin-geolocation”插件。
添加到$ionicPlatform.ready(...)下的基本控制器
navigator.geolocation.getCurrentPosition(function(position) {
var coords = {};
coords.updated = new Date();
coords.latitude = position.coords.latitude.toFixed(6);
coords.longitude = position.coords.longitude.toFixed(6);
coords.altitude = position.coords.altitude + ' m';
coords.accuracy = position.coords.accuracy + ' m';
coords.altitudeAccuracy = position.coords.altitudeAccuracy + ' m';
coords.heading = position.coords.heading + '\u00b0';
coords.speed = position.coords.speed + ' m/s';
console.log('Fetched Location...' + geoText);
return position;
}, function(err) {
Logger.error(err.message);
}, {
timeout: 10000,
enableHighAccuracy: true
});
当我在 iOS / Android 中模拟/运行时,它会抛出
错误消息:/www/index.html 想使用您的位置
如果有人可以提供帮助,我将不胜感激。
【问题讨论】:
-
您无法在设备模拟器中真正测试 cordova 插件。您是否尝试过构建并将其安装在实际设备上?或者您可以使用 intelxdk software.intel.com/en-us/intel-xdk 导入您的项目,然后使用调试选项卡将其推送到设备并拥有实时调试器,以便在真实设备上测试 cordova 插件并能够对其进行调试。
-
是的@Jess,我在我的手机(Android 和 iOS)上试过。感谢您的回复。该插件实际上工作正常,我担心的是它会弹出“.../Index.html 希望使用您的位置消息”(除了应用程序级别的确认)。
-
是的,我们刚开始在 ios 8.4.1 中遇到此问题,但在 android 上没有。你有没有设法找到解决办法?
-
@JessPatton,请查看我的答案以获取解决方案
-
好的,我试试看。谢谢
标签: cordova geolocation ionic-framework cordova-plugins ngcordova