zoukankan      html  css  js  c++  java
  • H5定位的实现

    <!DOCTYPE html>
    <html>
    <body>
    	<p id="demo">点击这个按钮,获得您的坐标:</p>
    	<button οnclick="getLocation()">试一下</button>
    	<script>
    		var x = document.getElementById("demo");
    		function getLocation() {
    			if (navigator.geolocation) {
    				navigator.geolocation.getCurrentPosition(showPosition, showError);
    			} else {
    				x.innerHTML = "Geolocation is not supported by this browser.";//浏览器不支持定位
    			}
    		}
    		function showPosition(position) {
    			x.innerHTML = "Latitude: " + position.coords.latitude
    					+ "<br />Longitude: " + position.coords.longitude;
    		}
    		function showError(error) {
    			switch (error.code) {
    			case error.PERMISSION_DENIED:
    				x.innerHTML = "User denied the request for Geolocation.";//用户不允许地理定位
    				break;
    			case error.POSITION_UNAVAILABLE:
    				x.innerHTML = "Location information is unavailable.";//无法获取当前位置
    				break;
    			case error.TIMEOUT:
    				x.innerHTML = "The request to get user location timed out.";//操作超时
    				break;
    			case error.UNKNOWN_ERROR:
    				x.innerHTML = "An unknown error occurred.";//未知错误
    				break;
    			}
    		}
    	</script>
    </body>
    </html>

  • 相关阅读:
    <摘录>如何在64位linux强制编译32位应用程序
    Ubuntu安装Java
    Mybatis学习
    Java小工具Lombok
    jenkins忘记admin密码的处理方法
    list删除元素
    ConcurrentHashMap详解
    用户登录
    SpringDemo01
    SpringBoot Eclipse 热部署
  • 原文地址:https://www.cnblogs.com/dulinan/p/12033044.html
Copyright © 2011-2022 走看看