lnglat.html
3.7 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>设备巡检系统定位服务</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
border: 0;
}
body {
position: absolute;
width: 100%;
height: 100%;
text-align: center;
}
#pos-area {
background-color: #009DDC;
margin-bottom: 10px;
width: 100%;
overflow: scroll;
text-align: left;
color: white;
}
#demo {
height: 400px;
font-size: small;
}
button {
margin-bottom: 10px;
padding: 12px 8px;
width: 42%;
border-radius: 8px;
background-color: #009DDC;
color: white;
}
#address{
width:96%;
float: left; padding-left:10px ;text-align: left;
}
</style>
<script type="text/javascript" src="https://mapapi.qq.com/web/mapComponents/geoLocation/v/geolocation.min.js"></script>
<script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
</head>
<body>
<div id="pos-area">
<p id="demo"></p>
</div>
<div id="btn-area">
<button onClick="geolocation.getLocation(showPosition)">获取精确定位信息</button>
</div>
<p id="address"></p>
<script type="text/JavaScript">
var marker ;
var circle ;
//初始化地图
var map = new TMap.Map("demo", {
zoom: 15, //设置地图缩放级别
});
var geolocation = new qq.maps.Geolocation("MTEBZ-2TF3X-HWD4S-TRNGR-EDRYS-XJBO3", "myapp");
function showPosition(position) {
document.getElementById("address").innerHTML = "经度:"+position.lng+"<br/>纬度:"+position.lat+"<br/>地址:"+position.addr
var center = new TMap.LatLng(position.lat, position.lng);
map.setCenter(center);
if(marker){
marker.setMap(null);
marker = null;
}
if(circle){
circle.setMap(null);
circle = null;
}
//初始化marker
marker = new TMap.MultiMarker({
id: "marker-layer", //图层id
map: map,
styles: { //点标注的相关样式
"marker": new TMap.MarkerStyle({
"width": 25,
"height": 35,
"anchor": { x: 16, y: 32 },
"src": "https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/markerDefault.png"
})
},
geometries: [{ //点标注数据数组
"id": "demo",
"styleId": "marker",
"position": center,
"properties": {
"title": "marker"
}
}]
});
circle = new TMap.MultiCircle({
map,
styles: { // 设置圆形样式
'circle': new TMap.CircleStyle({
'color': 'rgba(41,91,255,0.16)',
'showBorder': true,
'borderColor': 'rgba(41,91,255,1)',
'borderWidth': 2,
}),
},
geometries: [{
styleId: 'circle',
center: center,
radius: {$lnglatInfo['distance']},
}],
});
};
</script>
</body>
</html>