Browser to get longitude and latitude position of mobile phone

Time:2020-1-1
function getAddr() {
    window.navigator.geolocation.getCurrentPosition(
        function (position) {
            var longitude = position.coords.longitude;
            var latitude = position.coords.latitude;
            alert(longitude);
            alert(latitude);
        },
        function onError(error) {
            //alert(error.message);
            switch (error.code) {
                case error.PERMISSION_DENIED:
                    Alert ("you refuse to request a geographic location");
                    break;
                case error.POSITION_UNAVAILABLE:
                    Alert ("location information is not available");
                    break;
                case error.TIMEOUT:
                    Alert ("request for your geographic location timed out");
                    break;
                case error.UNKNOWN_ERROR:
                    Alert ("unknown error");
                    break;
            }
        }
    );
};

 

Where the position of latitude and longitude cannot be obtained:

1. The URL must be a domain name and cannot be accessed directly by IP, otherwise the mobile browser will directly refuse the change request.

2. The browser of iPhone (including wechat scanning code to enter the website) can’t obtain longitude and latitude for the website calling HTTP through personal test, which is the consideration of Apple mobile phone security. If HTTPS website is used, the certificate must also be a valid certificate (when invalid certificate is accessed, the browser will prompt whether the website is unsafe to continue to visit, even if “continue to visit” can’t obtain longitude and latitude Degree.

3. When acquiring longitude and latitude, users will be asked if they agree to acquire it. If users refuse, they will not be able to acquire it.

4. The computer browser cannot obtain the latitude and longitude, although there will be pop-up requests.