Диалоговое окно «Разрешение GPS-геолокации» не отображается в iOS - PullRequest
0 голосов
/ 17 марта 2020

Я построил очень простую карту с помощью Phonegap / Cordova. В этом приложении я использую геолокации api + gps. В моем телефоне Android все работает хорошо. Я получаю координаты, и появляется окно разрешения с просьбой разрешить данные о местоположении. Но когда я тестирую в своем iphone, я не получаю приглашение и GPS lo go не появляется. Координаты далеко на iphone. Что я делаю не так?

config. xml

<!-- 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
);
...