www/index.html 想使用您当前的位置

编程入门 行业动态 更新时间:2024-10-11 17:29:23
本文介绍了www/index.html 想使用您当前的位置 - Ionic Framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我搜索了与基于地理位置的警报问题相关的各种论坛和帖子;出于某种原因,在我的情况下没有任何技术起作用.

I searched various forums and posts related to GeoLocation based alert issue; For some reason no technique worked in my case.

在我的 Ionic 框架项目中添加了cordova-plugin-geolocation"插件.

Added "cordova-plugin-geolocation" plugin to my Ionic Framework Project.

在 $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 中模拟/运行时,它会抛出

When I emulate / run in iOS / Android it throws

错误消息:/www/index.html 想使用您的位置

Error Message: /www/index.html would like to use Your Location

如果有人可以提供帮助,我将不胜感激.

I would greatly appreciate if someone can help.

推荐答案

我按照这个解决了这个问题

I resolved this issue by following this

为 Location 创建了一个新的 Service,如下所示

Created a new Service for Location as follows

.service('LocationService', function($q) { this.fetch = function() { var deferred = $q.defer(); navigator.geolocation.getCurrentPosition(function(position) { deferred.notify('Fetching Location...') 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'; deferred.resolve(position); }, function(err) { deferred.reject(err); }, { timeout: 10000, enableHighAccuracy: true }); return deferred.promise; } })

那么我们将服务称为

Location.fetch().then(function(pos){...})

在 $ionicPlatform.ready(..) 内或添加到按钮 ng-click 以获取位置.

within $ionicPlatform.ready(..) or add to a button ng-click to fetch location.

根本原因:我相信,当我们在任何控制器中直接调用 Location.fetch() 或 navigator.geolocation.. 时,它会在最初加载控制器时执行.这可能会在 Cordova/Ionic 平台准备好之前被触发,因此我们会收到额外的/不需要的警报,指出 www/index.html 正在尝试使用位置作为我的问题状态.

Root Cause: What I believe is that when we call Location.fetch() or navigator.geolocation.. directly in any controllers, its executed when the controllers are loaded initially. This might get fired before Cordova / Ionic platform is ready and hence we get the additional / unwanted alert mentioning that www/index.html is trying to use location as my problem states.

更多推荐

www/index.html 想使用您当前的位置

本文发布于:2023-11-27 18:59:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   您当前   www   index   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!