__uniappmap.html
8.94 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta 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>
html,
body,
.container {
margin: 0;
padding: 0;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: #000000;
}
iframe {
width: 100%;
height: 100%;
display: block;
}
.actTonav {
display: none;
position: absolute;
right: 16px;
bottom: 56px;
width: 60px;
height: 60px;
border-radius: 60px;
}
</style>
</head>
<body>
<div id="container" class="container">
<iframe id="map" allow="geolocation" seamless sandbox="allow-scripts allow-same-origin allow-forms" frameborder="0"></iframe>
<!-- 去这里 -->
<div id="actTonav" class="actTonav"></div>
</div>
<script>
var loc;
var serviceWebview;
var back = function () {
var webview = plus.webview.currentWebview()
if (webview.__uniapp_dark) {
plus.navigator.setStatusBarStyle('dark')
}
webview.close('auto');
};
var isIos = !!navigator.userAgent.match(/iPhone|iPad|iPod/i);
/**
* 调用系统第三方程序进行导航
*/
function openSysMap(lat, lng, title) {
/**
* 网页版地图源
*/
var mapsSourceWeb = [{
title: '腾讯地图网页版',
getUrl: function () {
var url
url = 'https://apis.map.qq.com/uri/v1/routeplan?type=drive' + '&to=' +
encodeURIComponent(title) + '&tocoord=' + encodeURIComponent(lat + ',' + lng) +
'&referer=APP'
return url
}
},
{
title: '谷歌地图网页版',
getUrl: function () {
var url
url = 'https://maps.google.cn/?daddr=' + encodeURIComponent(title) + '&sll=' +
encodeURIComponent(lat + ',' + lng)
return url
}
}
]
/**
* APP版地图源
*/
var mapsSource = [{
title: '高德地图',
pname: 'com.autonavi.minimap',
action: !isIos ? 'amapuri://' : 'iosamap://',
getUrl: function () {
var url
if (!isIos) {
url = 'amapuri://route/plan/'
} else {
url = 'iosamap://path'
}
url += '?sourceApplication=APP&dname=' + encodeURIComponent(title) + '&dlat=' + lat +
'&dlon=' + lng + '&dev=0'
return url
}
},
{
title: '百度地图',
pname: 'com.baidu.BaiduMap',
action: 'baidumap://',
getUrl: function () {
var url
url = 'baidumap://map/direction?destination=' + encodeURIComponent('latlng:' + lat +
',' + lng + '|name:' + title) + '&mode=driving&src=APP'
return url
}
},
{
title: '腾讯地图',
pname: 'com.tencent.map',
action: 'qqmap://',
getUrl: function () {
var url
url = 'qqmap://map/routeplan?type=drive' + (isIos ? ('&from=' + encodeURIComponent(
'我的位置')) : '') + '&to=' + encodeURIComponent(title) + '&tocoord=' +
encodeURIComponent(lat + ',' + lng) + '&referer=APP'
return url
}
},
{
title: '谷歌地图',
pname: 'com.google.android.apps.maps',
action: 'comgooglemapsurl://',
getUrl: function () {
var url
if (!isIos) {
url = 'https://maps.google.com/'
} else {
url = 'comgooglemapsurl://maps.google.com/'
}
url += '?daddr=' + encodeURIComponent(title) + '&sll=' + encodeURIComponent(lat + ',' +
lng)
return url
}
},
]
var maps = []
mapsSource.forEach(function (mapsSource) {
var installed = plus.runtime.isApplicationExist({
pname: mapsSource.pname,
action: mapsSource.action,
})
if (installed) {
maps.push(mapsSource)
}
})
if (isIos) {
maps.unshift({
title: 'Apple 地图',
getUrl: function () {
var url
url = 'https://maps.apple.com/?daddr=' + encodeURIComponent(title) + '&sll=' +
encodeURIComponent(lat + ',' + lng)
return url
}
})
}
if (maps.length === 0) {
maps = maps.concat(mapsSourceWeb)
}
plus.nativeUI.actionSheet({
title: '导航方式',
cancel: '取消',
buttons: maps,
}, function (res) {
var index = res.index
var map
if (index > 0) {
map = maps[index - 1]
plus.runtime.openURL(map.getUrl(), function () {}, map.pname)
}
})
}
window.__chooseLocationConfirm__ = function () {
if (!loc) {
plus.nativeUI.alert('您尚未选择位置!');
return;
}
serviceWebview.evalJS('window.__chooseLocationCallback__&&__chooseLocationCallback__(' + JSON.stringify(
loc) + ')');
back();
}
document.addEventListener('plusready', function () {
serviceWebview = plus.webview.getWebviewById('__W2A_CONTEXT_') || plus.webview.getLaunchWebview();
plus.key.addEventListener('backbutton', back);
})
var mapElem = document.getElementById('map');
var defaultReferer = 'wxdevtools';
var defaultKey = 'JMRBZ-R4HCD-X674O-PXLN4-B7CLH-42BSB';
window.__openLocation__ = function (params) {
var key = params.key || defaultKey;
var referer = params.referer = defaultReferer;
var latitude = params.latitude;
var longitude = params.longitude;
var scale = params.scale;
var name = params.name;
var address = params.address;
var marker = 'coord:' + latitude + ',' + longitude;
if (name) {
marker += ';title:' + encodeURIComponent(name);
}
if (address) {
marker += ';addr:' + encodeURIComponent(address);
}
var url = 'http://apis.map.qq.com/tools/poimarker?type=0&marker=' + marker + '&key=' + defaultKey +
'&referer=' + referer;
mapElem.src = url;
var actTonav = document.getElementById('actTonav')
actTonav.style.display = 'block';
actTonav.onclick = function () {
openSysMap(latitude, longitude, name)
}
};
window.__chooseLocation__ = function (params) {
var params = params || {};
var key = params.key || defaultKey;
var referer = params.referer = defaultReferer;
var coord = params.coord || {};
var lat = coord.lat;
var lng = coord.lng;
var coordtype = coord.type || 5;
var url = 'http://apis.map.qq.com/tools/locpicker?type=1&search=1&coord=' + (lat && lng ? (lat + ',' +
lng) : '') + '&coordtype=' + coordtype + '&key=' + defaultKey + '&referer=' + referer;
mapElem.src = url;
};
window.addEventListener('message', function (event) {
var _loc = event.data;
if (_loc && _loc.module == 'locationPicker') {
loc = _loc;
}
}, false);
</script>
</body>
</html>