-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
50 lines (50 loc) · 1.48 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>百度地图Demo</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=47FQtS6XkphGqmZ5nSEj6WTSTwE8SGaT"></script>
<style>
* {
margin: 0;
padding: 0;
}
html,body {
height: 100%;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = new BMap.Map('map');
var point = new BMap.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
map.addControl(new BMap.MapTypeControl());
map.setCurrentCity('北京');
map.enableScrollWheelZoom(true);
var marker = new BMap.Marker(point); //创建标注
map.addOverlay(marker); //将标注添加到地图上
marker.setAnimation(BMAP_ANIMATION_BOUNCE);
//html5 新特性有哪些? geolocation 定位
function updateLocation(position) {
// console.log(position);
}
function handleLocationError(error) {
map.panTo(new BMap.Point(115.833051,28.726072));
}
if(navigator.geolocation) {
// alert('您的浏览器支持定位功能');
navigator.geolocation.getCurrentPosition(
updateLocation, handleLocationError);
} else {
alert('目前暂不支持该功能');
}
</script>
</body>
</html>