首页 > 解决方案 > 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
);

标签: iosiphonegeolocationgpsphonegap

解决方案


推荐阅读