z***@163.com
z***@163.com
  • 发布:2017-03-21 11:23
  • 更新:2017-03-21 11:34
  • 阅读:2447

mui--Maps定位问题

分类:MUI

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>Map Example</title>
<script type="text/javascript">
var em=null,map=null;
// H5 plus事件处理
function plusReady(){
// 确保DOM解析完成
if(!em||!window.plus||map){return};
map = new plus.maps.Map("map");
map.centerAndZoom( new plus.maps.Point(116.3977,39.906016), 12 );
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
// DOMContentloaded事件处理
document.addEventListener("DOMContentLoaded",function(){
em=document.getElementById("map");
plusReady();
},false);
// 打开用户位置
function showUserLocation(){
map.showUserLocation( true );
}
// 关闭用户位置
function hideUserLocation(){
map.showUserLocation( false );
}
// 获取是否打开用户位置
function isUserLocation(){
alert( map.isShowUserLocation() );
}
</script>
<style type="text/css">

map {

width: 100%;  
position: fixed;  
top: 100px;  
bottom: 0px;  
line-height: 200px;  
text-align: center;  
background: #FFFFFF;  

}
</style>
</head>
<body>
获取是否显示用户位置<br/>
<button onclick="showUserLocation()">显示用户位置</button>
<button onclick="hideUserLocation()">关闭用户位置</button><br/>
<button onclick="isUserLocation()">是否显示用户位置</button>
<div id="map">地图加载中...</div>
</body>
</html>

点击获取用户位置,还是显示在天安门,(手机端权限已经打开,GPS定位也打开了)

2017-03-21 11:23 负责人:无 分享
已邀请:
rodgerz

rodgerz

显示用户位置,只是在地图上显示你的位置,并不代表定位到用户位置

先调用map.getUserLocation()  获取坐标,再使用map.setCenter() 设置地图中心点位置

具体参考plus.maps.Map

该问题目前已经被锁定, 无法添加新回复