-
Notifications
You must be signed in to change notification settings - Fork 0
/
map5.html
142 lines (114 loc) · 3.6 KB
/
map5.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>加油站</title>
<style type="text/css">
*{
margin:0px;
padding:0px;
}
body, button, input, select, textarea {
font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
p{
width:603px;
padding-top:3px;
margin-top:10px;
overflow:hidden;
}
#container {
min-width:603px;
min-height:767px;
}
</style>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
<script>
var searchService,map,markers = [];
var init = function() {
var center = new qq.maps.LatLng(39.936273,116.44004334);
map = new qq.maps.Map(document.getElementById('container'),{
center: center,
zoom: 13
});
//初始化位置
//获取城市列表接口设置中心点
citylocation = new qq.maps.CityService({
complete : function(result){
map.setCenter(result.detail.latLng);
}
});
//调用searchLocalCity();方法 根据用户IP查询城市信息。
citylocation.searchLocalCity();
//绑定单击事件添加参数
qq.maps.event.addListener(map, 'click', function(event) {
//清屏
//点击时间调用方法:搜索
//search();
//创建marker
//点击创建标记
/* var centers = new qq.maps.LatLng(event.latLng.getLat(),event.latLng.getLng());
var marker = new qq.maps.Marker({
position: centers,
map: map
});*/
searchKeyword(event.latLng.getLat(),event.latLng.getLng());
/*alert('您点击的位置为: [' + event.latLng.getLat() + ', ' +
event.latLng.getLng() + ']');*/
//设置圆形
new qq.maps.Circle({
center:new qq.maps.LatLng(event.latLng.getLat(),event.latLng.getLng()),
radius: 2000,
map: map
});
});
var latlngBounds = new qq.maps.LatLngBounds();
//调用Poi检索类
searchService = new qq.maps.SearchService({
complete : function(results){
var pois = results.detail.pois;
for(var i = 0,l = pois.length;i < l; i++){
var poi = pois[i];
latlngBounds.extend(poi.latLng);
var marker = new qq.maps.Marker({
map:map,
position: poi.latLng
});
marker.setTitle(i+1);
markers.push(marker);
}
map.fitBounds(latlngBounds);
}
});
}
//清除地图上的marker
function clearOverlays(overlays) {
var overlay;
while (overlay = overlays.pop()) {
overlay.setMap(null);
}
}
//调用poi类信接口
function searchKeyword(Lat,Lng) {
// var keyword = document.getElementById("keyword").value;
var keyword="加油站"
region = new qq.maps.LatLng(Lat,Lng);
searchService.setPageCapacity(5);
searchService.searchNearBy(keyword, region, 2000);//根据中心点坐标、半径和关键字进行周边检索。
}
</script>
</head>
<body onload="init()">
<div>
<!--
时间:2018-05-15
描述:
<input id="keyword" type="textbox" value="酒店">
<input type="button" value="search" onclick="searchKeyword()">
-->
</div>
<div id="container"></div>
</body>
</html>