-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
54 lines (54 loc) · 1.66 KB
/
map.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!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 getUserLocation(){
map.getUserLocation( function ( state, point ){
if( 0 == state ){
alert( JSON.stringify(point) );
}else{
alert( "Failed!" );
}
} );
}
</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="getUserLocation()">获取位置</button>
<div id="map">地图加载中...</div>
</body>
</html>