旁观自己 善待朝夕|

猫老板的豆

园龄:9年4个月粉丝:52关注:0

H5获取地理位置

H5获取地理位置

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>H5获取地理位置</title>
	</head>
	<body>
		<script type="text/javascript">
			if(navigator.geolocation) {
				navigator.geolocation.getCurrentPosition(getLocation, showError);
			} else {
				alert("浏览器不支持")
			}

			// 返回经度和纬度
			function getLocation(position) {
				lat = position.coords.latitude;
				lng = position.coords.longitude;
				alert(lat + "," + lng);
			}

			//处理错误和拒绝
			function showError(error) {
				switch(error.code) {
					case error.TIMEOUT:
						alert("请求超时!请再试一次!");
						break;
					case error.POSITION_UNAVAILABLE:
						alert('我们找不到你的位置 Sorry!  ios10必须https才能访问定位');
						break;
					case error.PERMISSION_DENIED:
						alert('请允许地理位置访问!');
						break;
					case error.UNKNOWN_ERROR:
						alert('发生了未知错误!');
						break;
				}
			}
		</script>
	</body>
</html>

这里写图片描述

本文作者:猫老板的豆

本文链接:https://www.cnblogs.com/bingcola/p/16499344.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   猫老板的豆  阅读(408)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.