想使用H5获取位置信息,无奈ios10以上的,必须使用https的才能有获取位置的权限。没办法,改成利用百度地图API获取位置,demo如下,参考的API文档地址:http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a7b0
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body,html,#allmap {
100%;
height: 100%;
overflow: hidden;
margin: 0;
font-family: "微软雅黑";
}
</style>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="http://api.map.baidu.com/api?v=2.0&ak=您申请的百度ak"></script>
<title>GPS转百度</title>
</head>
<body>
<div id="allmap"></div>
</body>
<script type="text/javascript">
$(function() {
// 百度地图API功能
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r) {
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var point = r.point,
lng = point.lng,
lat = point.lat;
var point = new BMap.Point(lng, lat);
var map = new BMap.Map("allmap");
map.centerAndZoom(point, 15);
var marker = new BMap.Marker(point);// 创建标注
map.addOverlay(marker); // 将标注添加到地图中
var point1 = new BMap.Point(116.416524,40.076273);
var meter = map.getDistance(point, point1);
alert("两点之间的距离为:" + meter + "米");
}
else {
alert('failed'+this.getStatus());
}
},{enableHighAccuracy: true});
});
</script>
</html>