-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
63 lines (58 loc) · 1.34 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
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>html5百度地图:可以获取别人的位置</title>
</head>
<style>
body,html,#map{
overflow: hidden;
margin:0;
padding:0;
width: 100%;
height: 100%;
}
#input{
height: 20px;
width: 200px;
position: fixed;
top:30%;
left: 50%;
}
</style>
<body>
<div id="map"></div>
<input type="text" onkeyup="search()" id="input">
</body>
<script src="http://api.map.baidu.com/api?v=2.0&ak=zcirHg8mr00iw7oPmfqqfA5wZCkkLd9t"></script>
<script>
// console.log(navigator);
//getCurrentPosition HTML5获取定位信息的方法,接受两个函数
var map = new BMap.Map('map');
map.centerAndZoom("广州",16)
// 原生js获取经纬度
// navigator.geolocation.getCurrentPosition(function(data) {
// console.log(data);
// },function(error) {
// console.log(error);
// })
var local = new BMap.LocalSearch(map, {
renderOptions:{map: map}
});
//local.search("银行");
//百度方法获取经纬度
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
console.log(r);
var mk = new BMap.Marker(r.point);
map.addOverlay(mk);
map.panTo(r.point);
},function(error){
})
function search(){
var value = document.getElementById('input').value;
console.log(value)
local.search(value);
}
</script>
</html>