ios - GPS 地理位置权限对话框未在 iOS 中显示
问题描述
我用 Phonegap/Cordova 构建了一个非常简单的地图。在这个应用程序中,我使用地理定位 api + gps。在我的 Android 手机上一切正常。我得到坐标并且出现许可框,要求允许位置数据。但是当我在我的 iphone 中测试时,我没有收到提示,也没有出现 GPS 标志。iphone上的坐标太差了。我究竟做错了什么?
配置文件
<!-- According to the docs you only need this block -->
<!-- This plugin provides information about the device's location, such as latitude and longitude. -->
<plugin name="cordova-plugin-geolocation" spec="~4">
<variable name="GEOLOCATION_USAGE_DESCRIPTION" value="this app uses your location for maps." />
</plugin>
<!-- On iOS you'll get multiple access location prompts with cordova-plugin-geolocation 4.0.1 -->
<!-- And the app will not save the access location permisssion in the iOS settings. -->
<!-- And on every start of your app it the access location dialog will wil re-appear. -->
<!-- It als odoe not show the permission in the required format for the Apple app store. -->
<!-- It's probably related to https://issues.apache.org/jira/browse/CB-13680 -->
<!-- If you override all the messages the app will show a properly formatted prompt and it will save the settings. -->
<platform name="ios">
<edit-config target="NSLocationAlwaysAndWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>This app uses your location for maps.</string>
</edit-config>
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>This app uses your location for maps.</string>
</edit-config>
<edit-config target="NSLocationAlwaysUsageDescription" file="*-Info.plist" mode="merge">
<string>This app uses your location for maps.</string>
</edit-config>
</platform>
<!-- On Android the cordova-plugin-geolocation version 4.0.1 will not prompt for the geolocation permissions -->
<!-- With these permission overrides the app will ask for the fine location permission anyway -->
<platform name="android">
<uses-permission name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
</platform>
地理位置.js
var latitude, longitude, accuracy;
function setGeolocation() {
var geolocation = window.navigator.geolocation.watchPosition(
function ( position ) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
accuracy = position.coords.accuracy;
console.log(
'lat: ' + latitude + ', '
+ 'lng: ' + longitude + ', '
+ 'accuracy: ' + accuracy + '<br />');
},
function () { /*error*/ }, {
maximumAge: 250,
enableHighAccuracy: true
}
);
window.setTimeout( function () {
window.navigator.geolocation.clearWatch( geolocation )
},
5000 //stop checking after 5 seconds
);
};
setGeolocation();
window.setInterval( function () {
setGeolocation();
},
15000 //check every 15 seconds
);
解决方案
推荐阅读
- sql - 编写一个 SELECT 语句,从 db1.MyGuitarShop.Products 表中返回这些列:
- flutter - 向上滚动时隐藏底部导航栏
- r - 为新创建的因子组创建一个新列分组数字 (num)
- winforms - 如果主窗体或它所在的任何用户控件被移动或调整大小,则更改窗体位置
- angular - 在父视图中渲染 elementReference
- spring-boot - 使用 HttpURLConnection 使用 Mockito 进行单元测试
- c++ - 查询c++中函数的默认返回类型
- c - 可以打开读取传感器数据
- apache-spark - 如何以追加模式将“所有字符串”数据帧写入 Spark JDBC 到具有 int 和 varchar 列的目标表
- email - 预期响应代码 250,但得到代码“550”,消息“550 5.7.1 Relaying denied”