choose_address.html
13.3 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title></title>
<!--<link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>-->
<link rel="stylesheet" href="../../assets/icon/iconfont.css">
<script src="../../assets/js/fontsize.js"></script>
<link rel="stylesheet" href="../../assets/css/weui.min.css">
<link rel="stylesheet" href="../../assets/css/api.css" />
<!-- <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>-->
<style type="text/css">
body {
padding-bottom: 1rem;
}
.city_top {
position: fixed;
left: 0;
top: 0;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.25rem;
font-size: 0.3rem;
color: #333;
border: 1px solid #f5f5f5;
background-color: #fff;
}
.city_name_box {
display: flex;
align-items: center;
flex: 1;
}
.city_name_box .iconfont {
margin: 0 0.1rem 0 0;
}
.city_input {
flex: 3;
margin: 0 0.1rem 0 0.1rem;
background-color: #f2f2f2;
padding: 0 0 0 0.2rem;
border-radius: 0.1rem;
}
.city_input input {
width: 100%;
padding: 0.2rem 0.25rem;
color: #333;
font-size: 0.26rem;
}
.city_input input::-webkit-input-placeholder {
color: #aaa;
}
.city_item {
padding: 0.3rem 0.25rem;
color: #999;
font-size: 0.26rem;
display: flex;
justify-content: space-between;
}
.choose_box {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 0.24rem;
color: #333;
padding: 0.2rem 0.25rem;
border-bottom: 1px solid #f2f2f2;
margin-top: 1.3rem;
}
.position {
display: flex;
align-items: center;
}
.position span {
margin-left: 0.2rem;
}
.city_name {
color: #333;
font-size: 0.3rem;
}
.city_address {
font-size: 0.26rem;
}
.my_address {
margin: 0.25rem;
}
.my_address .iconfont {
margin: 0 0.1rem 0 0;
color: #ccc;
}
.address_title {
font-size: 14px;
color: #999;
}
.choose_city {
font-size: 18px;
}
.address_item {
color: #424242;
font-size: 16px;
padding: 0.26rem 0.5rem 0.26rem 0.2rem;
border-bottom: 1px solid #f2f2f2;
}
</style>
</head>
<body>
<div id="loadStart"></div>
<div id="app" v-cloak>
<div id="container"></div>
<div class="city_top">
<div class="city_name_box" @click="choose_city_fun">
<span class="iconfont icon-dizhi"></span>
<div class="clamp1">{{cityname}}</div>
</div>:
<div class="city_input"><input type="search" placeholder="请输入你的服务地址" v-model="keyword" @input="getCity"></div>
<div class="main_color" @click="search_word">搜索</div>
</div>
<div class="choose_box" @click="choose_now">
<span class="choose_city">{{street}}</span>
<div class="main_color position"><span class="iconfont icon-zhongxindingwei"></span><span>重新定位</span></div>
</div>
<div v-if="address_show">
<div class="my_address">
<div class="address_title"><span class="iconfont icon-shouye"></span><span> 我的服务地址</span></div>
<div class="address_item nodata" v-if="user_address_list.length==0">暂无服务地址</div>
<div class="address_item" v-for="(item,index) in user_address_list" @click="choose_address(item.address,item.address_info,item.lon,item.lat)" v-else>
<span>{{item.address}}{{item.address_info}}</span>
</div>
</div>
<div class="my_address">
<div class="address_title"><span class="iconfont icon-dizhi"></span><span>我的附近地址</span></div>
<div class="address_item" v-for="(item,index) in nearList" @click="choose_address(item.address,'',item.lon,item.lat)">
<span>{{item.address}}</span>
</div>
</div>
</div>
<div v-for="(item,index) in keywords" class="city_item" @click="choose_address(item.address,item.name,item.lon,item.lat)" v-else>
<div>
<div class="city_name">{{item.name}}</div>
<div class="city_address">{{item.address}}</div>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript" src="../../assets/js/weui.min.js"></script>
<script type="text/javascript" src="../../assets/js/api.js"></script>
<script type="text/javascript" src = 'https://webapi.amap.com/maps?v=1.4.4&test=true&key=ef53760bd959a4df08b7d4587280e642&&plugin=AMap.ToolBar,AMap.IndoorMap'></script>
<script type="text/javascript" src="../../assets/js/public.js"></script>
<script type="text/javascript" src="../../assets/js/fastclick.js"></script>
<script>
new FastClick(document.body);
</script>
<script type="text/javascript" src="../../assets/js/vue.min.js"></script>
<script type="text/javascript" src="../../assets/js/axios.min.js"></script>
<script type="text/javascript" src="../../assets/icon/iconfont.js"></script>
<script type="text/javascript" src="https://cache.amap.com/lbs/static/PlaceSearchRender.js"></script>
<script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
<script>
var map = {}
map = new AMap.Map('container');
var app = new Vue({
el: '#app',
data: {
cityname: '',
lat: '',
lng: '',
keyword: '',
keywords: [],
cities: [],
street: '',
nearList: [],
user_address_list: [],
address_show: true,
latitude: '',
longitude: '',
//经度
lng: '',
//纬度
lat: '',
map: {},
//经纬度
centerPoint: []
},
created: function() {
// apiready = function() {
this.get_city();
this.getUsedAddress()
// }
// app.getNearBy();
// app.cityname = getcity() ? getcity() : api.pageParam.cityname;
// api.addEventListener({
// name: 'city'
// }, function (ret, err) {
// // alert(JSON.stringify(ret));
// app.cityname = ret.value.city;
// });
// app.getUsedAddress();
},
methods: {
// 获取我的服务地址
getUsedAddress: function() {
var header = {
"XX-Device-Type": getDevice(),
'XX-Token': getToken()
};
console.log(header)
getRequest('post', 'portal/Goods/getUsedAddress', null, header).then(function(res) {
//alert(JSON.stringify(res));
if(res.data.code == 1) {
app.user_address_list = res.data.data;
toastMsg(res.data.msg)
}
loadEnd();
})
},
// 重新获取当前定位信息
choose_now: function() {
toastMsg('正在重新定位');
app.get_city()
setTimeout(function() {
// api.hideProgress();
}, 2000)
},
// 定位当前城市
get_city: function() {
var app = this ;
// app.map = new AMap.Map('container', {});
map.plugin('AMap.Geolocation', function() {
var geolocation = new AMap.Geolocation({
// 是否使用高精度定位,默认:true
enableHighAccuracy: true,
// 设置定位超时时间,默认:无穷大
timeout: 10000
});
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, 'complete', onComplete)
AMap.event.addListener(geolocation, 'error', onError)
function onComplete(data) {
alert(JSON.stringify(data));
app.cityname = data.addressComponent.province;
console.log(app.cityname);
app.lng = data.position.lng;
app.lat = data.position.lat;
// console.log(app.lng);
// console.log(app.lat);
//
// 获取附近地址
app.map = new AMap.Map('container', {});
AMap.service(["AMap.PlaceSearch"], function() {
var placeSearch = new AMap.PlaceSearch({
pageSize: 10, // 每页10条
pageIndex: 1, // 获取第一页
city: app.cityname // 指定城市名(如果你获取不到城市名称,这个参数也可以不传,注释掉)
});
// 第一个参数是关键字,这里传入的空表示不需要根据关键字过滤
// 第二个参数是经纬度,数组类型
// 第三个参数是半径,周边的范围
// 第四个参数为回调函数
placeSearch.searchNearBy(app.cityname, [app.lng, app.lat], 1000, function(status, result) {
console.log(JSON.stringify(status))
if(result.info === 'OK') {
var locationList = result.poiList.pois; // 周边地标建筑列表
//console.log(JSON.stringify(locationList))
app.nearList = locationList // 生成地址列表html
// createLocationHtml(locationList);
} else {
console.log('获取位置信息失败!');
}
});
});
}
function onError(erro) {
// 定位出错
toastMsg('请开启定位功能')
}
})
},
//获取当前坐标
getNowCity(){
mapObj = new AMap.Map('iCenter');
mapObj.plugin('AMap.Geolocation', function () {
geolocation = new AMap.Geolocation({
enableHighAccuracy: true,//是否使用高精度定位,默认:true
timeout: 10000, //超过10秒后停止定位,默认:无穷大
maximumAge: 0, //定位结果缓存0毫秒,默认:0
convert: true, //自动偏移坐标,偏移后的坐标为高德坐标,默认:true
showButton: true, //显示定位按钮,默认:true
buttonPosition: 'LB', //定位按钮停靠位置,默认:'LB',左下角
buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
showMarker: true, //定位成功后在定位到的位置显示点标记,默认:true
showCircle: true, //定位成功后用圆圈表示定位精度范围,默认:true
panToLocation: true, //定位成功后将定位到的位置作为地图中心点,默认:true
zoomToAccuracy:true //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
});
mapObj.addControl(geolocation);
geolocation.getCurrentPosition();
AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
});
function onComplete(obj){
var res = '经纬度:' + obj.position +
'\n精度范围:' + obj.accuracy +
'米\n定位结果的来源:' + obj.location_type +
'\n状态信息:' + obj.info +
'\n地址:' + obj.formattedAddress +
'\n地址信息:' + JSON.stringify(obj.addressComponent, null, 4);
alert(res);
}
function onError(obj) {
alert(obj.info + '--' + obj.message);
console.log(obj);
}
},
// 获取搜索地址
getCity: function() {
var app = this;
if(app.keyword == '') {
app.address_show = true;
} else {
app.address_show = false;
var aMap = api.require('aMap');
var placeSearchOptions = { //构造地点查询类
pageSize: 10,
pageIndex: 1,
city: app.cityname //城市
};
var placeSearch = new AMap.PlaceSearch(placeSearchOptions);
//关键字查询,您如果想修改结果展现效果,请参考页面:https://lbs.amap.com/fn/css-style/
placeSearch.search(app.keyword, callback);
var placeSearchRender = new Lib.AMap.PlaceSearchRender();
function callback(status, result) {
locationList = result.poiList.pois
// console.log(JSON.stringify(result));
app.keywords = locationList;
if(status === 'complete' && result.info === 'OK') {
placeSearchRender.autoRender({
placeSearchInstance: placeSearch,
methodName: "search",
methodArgumments: [app.keyword, callback],
data: result,
map: map,
panel: "panel"
});
}
}
}
},
// 搜索地址
search_word: function() {
var app = this;
if(app.keyword == '') {
toastMsg('请输入搜索内容')
} else {
app.getCity();
}
},
// 选择地址
choose_address: function(address, name, longitude, latitude) {
api.sendEvent({
name: 'choose_city',
extra: {
address: address,
name: name,
longitude: longitude,
latitude: latitude,
city: app.cityname
}
});
closeWindow();
},
// 切换城市
choose_city_fun: function() {
api.openWin({
url: '../index/city_win.html',
name: 'city_win'
});
$api.rmStorage('city')
},
getName: function(lon, lat) {
var aMap = api.require('aMap');
aMap.getNameFromCoords({
lon: lon,
lat: lat,
}, function(ret, err) {
if(ret.status) {
// alert(JSON.stringify(ret))
app.cityname = ret.city
} else {
// toastMsg(err.code);
}
});
}
}
})
</script>