Home > Web Front-end > H5 Tutorial > Sample code sharing for obtaining mobile phone GPS information using html5

Sample code sharing for obtaining mobile phone GPS information using html5

黄舟
Release: 2017-04-24 10:48:36
Original
5279 people have browsed it

html5 sample code sharing for obtaining mobile phone GPS information:

function getLocation() {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(showPosition, showError);
            } else {
                alert("浏览器不支持地理定位。");
            }
        }
 
        function showError(error) {
            switch (error.code) {
                case error.PERMISSION_DENIED:
                    alert("定位失败,用户拒绝请求地理定位");
                    break;
                case error.POSITION_UNAVAILABLE:
                    alert("定位失败,位置信息是不可用");
                    break;
                case error.TIMEOUT:
                    alert("定位失败,请求获取用户位置超时");
                    break;
                case error.UNKNOWN_ERROR:
                    alert("定位失败,定位系统失效");
                    break;
            }
        }
 
        function showPosition(position) {
            lat = position.coords.latitude; //纬度 
            lag = position.coords.longitude; //经度 
            alert('纬度:' + lat + ',经度:' + lag);
             
        }
Copy after login

The above is the detailed content of Sample code sharing for obtaining mobile phone GPS information using html5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template