


Detailed introduction to the steps to implement WeChat mini program using Tencent Map SDK
This article implements the use of Tencent Maps in WeChat Mini Programs Maps SDK steps are introduced in detail. Friends in need can refer to the following
Detailed explanation of using Tencent Maps SDK in WeChat Mini Programs And implementation steps
Recently, I used the mini program solution provided by Tencent Maps in a lottery service project, and I would like to share it with you!
It is very simple to use, but some functions still need to be improved.
Official document: lbs.qq.com/qqmap_wx_jssdk/index.html
Steps:
Application Developer key (key): Apply for key
Download WeChat Mini Program JavascriptSDK, WeChat Mini Program JavascriptSDK v1.0
Secure domain name setting, you need to add the domain name address apis.map.qq.com on the WeChat public platform
Mini program example
// 引入SDK核心类 var QQMapWX = require('../../libs/qqmap-wx-jssdk.js'); var qqmapsdk; Page({ onLoad: function () { // 实例化API核心类 qqmapsdk = new QQMapWX({ key: '申请的key' }); }, onShow: function () { // 调用接口 qqmapsdk.search({ keyword: '彩票', success: function (res) { console.log(res); }, fail: function (res) { console.log(res); }, complete: function (res) { console.log(res); } }); })
Result renderings:
Go to buy lottery.png
5. Core categories
5.1 Location search search(options:Object)
Search surrounding POIs through keywords, such as "hotels", "catering" and "entertainment" ""School" etc.
Go to the implementation of the lottery purchase interface:
5.1.1 buy.js
// 引入腾讯地图SDK核心类 var QQMapWX = require('../../utils/qqmap-wx-jssdk.js'); var util = require("../../utils/util.js"); var qqmapsdk; Page({ data: { resData: [] }, onLoad: function (options) { // 实例化腾讯地图API核心类 qqmapsdk = new QQMapWX({ key: 'HPNBZ-B426V-CZQPP-UN4R6-QYOF2-MYFU3'//此处使用你自己申请的key }); }, onShow: function () { var that = this; // 腾讯地图调用接口 qqmapsdk.search({ keyword: '彩票', page_size: 20, success: function (res) { console.log(res); var resData = res.data; for (var i = 0; i < resData.length; i++) { resData[i]._distance = util.formatDistance(resData[i]._distance);//转换一下距离的格式 } that.setData({resData: resData}); }, fail: function(res) { console.log(res); }, complete: function(res) { console.log(res); } }) } })
// utils/util.js /** * 将距离格式化 * <1000m时 取整,没有小数点 * >1000m时 单位取km,一位小数点 */ function formatDistance(num) { if (num < 1000) { return num.toFixed(0) + 'm'; } else if (num > 1000) { return (num / 1000).toFixed(1) + 'km'; } }
5.1.2 buy.wxml Main The style is weui
<view class="page"> <view wx:for="{{resData}}" wx:key="shop" class="pagebd"> <view bindtap="navTo" data-item="{{item}}"> <view class="weui-panel"> <view class="weui-panelbd"> <view class="weui-media-box weui-media-box_text"> <view class="weui-media-boxtitle weui-media-boxtitle_in-text">{{item.title}}</view> <view class="weui-media-boxdesc">{{item.address}}</view> <view class="weui-media-boxinfo"> <view class="weui-media-boxinfometa">电话:{{item.tel}}</view> <view class="weui-media-boxinfometa weui-media-boxinfometa_extra">距离:{{item._distance}}</view> </view> </view> </view> </view> </view> </view> </view>
5.2 Keyword input prompts getSuggestion(options:Object)
is used to obtain completions and prompts for input keywords to help users input quickly.
Example:
// 调用接口 qqmapsdk.getSuggestion({ keyword: '技术', success: function(res) { console.log(res); }, fail: function(res) { console.log(res); }, complete: function(res) { console.log(res); } });
5.3 Distance calculation calculateDistance(options:Object)
Calculate the walking or driving distance from one point to multiple points.
Example:
// 调用接口 qqmapsdk.calculateDistance({ mode: 'walking';//步行,驾车为'driving' to:[{ latitude: 39.984060, longitude: 116.307520 }, { latitude: 39.984572, longitude: 116.306339 }], success: function(res) { console.log(res); }, fail: function(res) { console.log(res); }, complete: function(res) { console.log(res); } });
5.4 There are also the following functions, so I won’t demonstrate them one by one.
getCityList(options:Object): Get the national city list data;
getDistrictByCityId(options:Object): Return the city list by city ID Districts and counties;
reverseGeocoder(options:Object): used to obtain completion and prompts for input keywords to help users quickly enter
geocoder(options:Object): Provides conversion from address description to the location coordinates, which is exactly the opposite of the process of reverse geocoder().
The above is the detailed content of Detailed introduction to the steps to implement WeChat mini program using Tencent Map SDK. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools
