H5地理定位

$("#btn").click(function() {
				if(navigator.geolocation) {
					navigator.geolocation.getCurrentPosition(showPosition, showError);
				} else {
					console.log("Geolocation is not supported by this breoser")
				}
			});
			
			var xhtml = '';
			
			/*function showPositon(position) {
				xhtml = 'x:' + position.coords.latitude + 'y:' + position.coords.longitude;
				$("#input").html(xhtml);
			}*/
			/*Google地图展示当前位置*/
			
			function showPosition(position) {
				var latlon = position.coords.latitude + "," + position.coords.longitude;

				var img_url = "http://maps.googleapis.com/maps/api/staticmap?center=" +
					latlon + "&zoom=14&size=400x300&sensor=false";
				xhtml = "<img src='" + img_url + "' />";
				$("#input").html(xhtml);
			}
			
			function showError(error) {
				switch(error.code) {
					case error.PERMISSION_DENIED:
						xhtml = "User denied the request for Geolocation."
						$("#input").html(xhtml);
						break;
					case error.POSITION_UNAVAILABLE:
						xhtml = "Location information is unavailable."
						$("#input").html(xhtml);
						break;
					case error.TIMEOUT:
						xhtml = "The request to get user location timed out."
						$("#input").html(xhtml);
						break;
					case error.UNKNOWN_ERROR:
						xhtml = "An unknown error occurred."
						$("#input").html(xhtml);
						break;
				}
			}
			Geolocation对象----其他有趣的方法
			watchPosition()---返回用户当前位置,并继续返回用户移动时的更新位置(就像汽车上的GPS)
			clearPosition()---停止watchPosition()方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值