当前位置:网站首页>Wechat applet coordinate location interface usage (II) map interface
Wechat applet coordinate location interface usage (II) map interface
2022-06-13 02:55:00 【Tianma 3798】
Use and arrangement of coordinate position interface of wechat applet ( Two )
Realize more map services in wechat applet , You can use Tencent map Api.
The following scenarios are using maps Api call .
official Api: Wechat applet JavaScript SDK | Tencent location service
One 、 Tencent maps are used in wechat apps Api technological process
1. Log in to the official website of Tencent maps , Apply for the secret key
2. download JavaScriptSDK, To project

3. Applet background , Domain name whitelist , Set up request Legitimate domain name , add to https://apis.map.qq.com
Initialization in the project , Use interface
var QQMapWX = require('../../../utils/qqmap-wx-jssdk.min');
var map = null; // initialization
map = new QQMapWX({
key: 'PNYBZ-XNV36-X64SW-EALEI-2C63E-6MFNJ'
});Two 、 Near the designated location “ key word ” Search for
// Near the designated location “ key word ” Search for
map.search({
keyword: ' Bank ',
location: {
latitude: '36.656858',
longitude: '116.916358'
},
success: res => {
console.info(res);
}
});
3、 ... and 、 Inverse analysis , Obtained by coordinates , Location name
// Inverse analysis , Obtained by coordinates , Location name
map.reverseGeocoder({
location: {
latitude: '36.656858',
longitude: '116.916358'
},
success: res => {
console.info(res);
}
});
Four 、 analysis , Get the coordinates corresponding to the position
// analysis , Get the coordinates corresponding to the position , Le Meng center, Jingshi Road, Huaiyin District, Jinan City 3 building 3103 room
map.geocoder({
address:' Le Meng center, Jingshi Road, Huaiyin District, Jinan City 3 building 3103 room ',
success:res=>{
console.info(res);
}
});
5、 ... and 、 Use maps , Route planning
// Use maps , Route planning
map.direction({
// mode: 'driving',
from: {
latitude: '36.656858',
longitude: '116.916358'
},
to: {
latitude: '36.440819',
longitude: '116.016219'
},
success: res => {
console.info(res);
}
});
Be careful : The interface here is to obtain the data of the planned route . If you want to show route planning , Please use Tencent map widget or polyline Decompress the coordinates .
polyline Decompress the coordinates , Show route to map Components :
<map longitude="{
{mapinfo.longitude}}"
latitude="{
{mapinfo.latitude}}"
scale="12"
polyline="{
{polyline}}"
show-location
></map> // Use maps , Route planning
var _this = this;
map.direction({
// mode: 'driving',
from: {
latitude: '36.656858',
longitude: '116.916358'
},
to: {
latitude: '36.440819',
longitude: '116.016219'
},
success: res => {
console.info(res);
var coors = res.result.routes[0].polyline;
var mapPolyline = [];
// Decompress the coordinates ( The coordinates of the returned point string , Compression by forward differential )
var kr = 1000000;
for (var i = 2; i < coors.length; i++) {
coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
}
// Put the decompressed coordinates into the point string array pl in
for (var i = 0; i < coors.length; i += 2) {
mapPolyline.push({
latitude: coors[i],
longitude: coors[i + 1]
})
}
// console.info(mapPolyline);
_this.setData({
['polyline']:[{
points: mapPolyline,
color: '#00ff00',
width: 4
}]
});
}
});
this.setData({
mapinfo: {
latitude: '36.656858',
longitude: '116.916358'
}
});Display the results :


more :
Use and arrangement of coordinate position interface of wechat applet ( One )
Wechat applet switch Style rewriting
Applet Image Component long press to identify supported codes
边栏推荐
- Ijkplayer source code - setting option 2
- Ijkplayer source code - audio playback
- CDN single page reference of indexbar index column in vant framework cannot be displayed normally
- [data analysis and visualization] key points of data drawing 11- precautions for radar chart
- Linked list: adding numbers in the linked list
- [data and Analysis Visualization] D3 introductory tutorial 2- building shapes in D3
- Wechat applet obtains the current location (startlocationupdate, onlocationchange, offlocationchange)
- Ffmpeg principle
- JS deconstruction assignment
- Word splitting problem
猜你喜欢

Summary of the latest IOS interview questions in June 2020 (answers)

Ijkplayer source code ---packetqueue

【 enregistrement pytorch】 paramètre et tampon des variables pytorch. Self. Register Buffer (), self. Register Paramètre ()

Prometheus node_ Exporter installs and registers as a service
![[data analysis and visualization] key points of data drawing 9- color selection](/img/76/0d707b3d2446b5cd8002cbc2834c5c.jpg)
[data analysis and visualization] key points of data drawing 9- color selection

Pycharm installation pyqt5 and its tools (QT designer, pyuic, pyrcc) detailed tutorial

Node uses post to request req Pit with empty body

Detailed explanation of data processing in machine learning (I) -- missing value processing (complete code attached)

How to destroy a fragment- How to destroy Fragment?

冲刺强基计划数学物理专题一
随机推荐
Stack: daily temperature
[data analysis and visualization] key points of data drawing 8- use of circular bar chart
【pytorch 记录】pytorch的变量parameter、buffer。self.register_buffer()、self.register_parameter()
Detailed installation tutorial of MATLAB r2019 B-mode ultrasound (complete installation files are attached)
Ijkplayer source code - choose soft decoding or hard decoding
Delphi implements adding a column of serial number to the CXGRID list
[data analysis and visualization] key points of data drawing 6- too many data groups
Beginner development process_ Project development FAQs
Radio design and implementation in IVI system
2019 - sorting out the latest and most comprehensive IOS test questions (including framework and algorithm questions)
My practice of SOA architecture project based on WCF
Digital IC Design -- FIFO design
js 解构赋值
Introduction to facial expression recognition system -- offline environment configuration
String: number of substring palindromes
Hash table: the time complexity of insert, delete and random access is O (1)
Introduction and download of common data sets for in-depth learning (with network disk link)
Vscode liveserver use_ Liveserver startup debugging
冲刺强基计划数学物理专题一
How to manage the IT R & D department?