Запросите разрешение на размещение всплывающих окон в мобильном браузере iOS - PullRequest
0 голосов
/ 15 мая 2018

Здравствуйте. Я использую нижеприведенный java-скрипт для разрешения местоположения, который работает нормально, когда мы открываем его в браузере рабочего стола и на устройстве Android, но всплывающее окно не работает на устройстве iOS.

(function () {
            function updatePermission(name, state) {
                console.log('update permission for ' + name + ' with ' + state);
            }

            function init() {
                var getPosBtn = document.querySelector('#getPositionBtn');
                // Check for Geolocation API permissions
                navigator.permissions.query({name:'geolocation'}).then(function(p) {
                    updatePermission('geolocation', p.state);
                    p.onchange = function() {
                        updatePermission('geolocation', this.state);
                    };
                });

                getPosBtn.addEventListener('click', function() {
                    getLocation();
                });

                $( document ).ready(function() {
                    getpermission();
                });

                function getpermission(){
                    navigator.geolocation.getCurrentPosition(
                        function(position) {
                            var geocoder;
                            var city;
                            geocoder = new google.maps.Geocoder();
                            var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                            geocoder.geocode({'latLng': latlng},function (results, status) {
                                if (status == google.maps.GeocoderStatus.OK) {
                                    if (results[0]) {
                                        var arrAddress = results;
                                        console.log(results);
                                    } else {
                                        console.log("address not found");
                                    }
                                } else {
                                    console.log("Geocoder failed due to: " + status);
                                }
                            });
                        },function(error) {
                            console.log(error);
                        },{enableHighAccuracy: true, maximumAge: 10000} 
                    );
                }

                function getLocation(){
                    navigator.geolocation.getCurrentPosition(
                        function(position) {
                            var geocoder;
                            var city;
                            geocoder = new google.maps.Geocoder();
                            var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                            geocoder.geocode({'latLng': latlng},function (results, status) {
                                if (status == google.maps.GeocoderStatus.OK) {
                                    if (results[0]) {
                                        var arrAddress = results;
                                        console.log(results);
                                        $('.location_input').val(results[0].formatted_address);
                                    } else {
                                        console.log("address not found");
                                    }
                                } else {
                                    console.log("Geocoder failed due to: " + status);
                                }
                            });
                        },function(error) {
                            console.log(error);
                        },{enableHighAccuracy: true, maximumAge: 10000} 
                    );
                }

            }
            init();
        })();

В двух случаях я запрашиваю разрешение у пользователя, когда он нажимает на значок местоположения и на загрузку страницы. Разрешение на загрузку страницы не работает ни на одном устройстве, но разрешение на нажатие события кнопки работает на устройстве Android.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...