-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaidumap.html
27 lines (27 loc) · 1.02 KB
/
baidumap.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
<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,#baidumap {width: 100%;height: 100%;overflow: hidden;margin:0;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=OgAufCYdHRO0k8xcceaqOLN4"></script>
<title>单击获取点击的结构化地址信息和经纬度</title>
</head>
<body>
<div id="baidumap"></div>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("baidumap"); // 创建Map实例
map.centerAndZoom("福州",12); // 初始化地图,设置城市和地图级别。
var gc = new BMap.Geocoder();
map.addEventListener("click",function(e) {
var pt = e.point;
gc.getLocation(pt, function(rs) {
var addComp = rs.addressComponents;
alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber + "\r\n" + pt.lng + "," + pt.lat);
});
});
</script>