Phone browsers get latitude and longitude location

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("您拒绝对获取地理位置的请求");
                    break;
                Case error.POSITION_UNAVAILABLE: 
                    Alert ( "location information is not available" );
                     BREAK ;
                 Case error.TIMEOUT: 
                    Alert ( "Ask your location timeout" );
                     BREAK ;
                 Case error.UNKNOWN_ERROR: 
                    Alert ( "unknown error" ) ;
                     BREAK ; 
            } 
        } 
    ); 
};

 

Unable to get latitude and longitude of the case:

1. The URL must be a domain name can not be directly accessed by ip, or change your phone's browser directly rejected the request.

2. iphone browsers (including micro-channel scan code into the site), pro-test call http site can not get to the latitude and longitude, it is Apple's mobile security reasons, if you use https Web site, the certificate must be valid certificate (certificate is invalid when a browser to access the site will be prompted whether to continue accessing unsafe, even though the "continued access" can not get latitude and longitude).

3. Get latitude and longitude will ask if the user agrees to acquire, the user refuses to do so naturally can not get to.

4. computer browser can not get latitude and longitude, although there will be pop request.

 

 

Guess you like

Origin www.cnblogs.com/hongwei918/p/11420502.html