小程序,WebService服務(wù)端,需要使用地圖服務(wù)的小伙伴可以認(rèn)真閱讀!!!
功能包括(位置定位及標(biāo)記標(biāo)點(diǎn), 輸入位置轉(zhuǎn)換經(jīng)緯度)滿足你的需求,廢話不多說(shuō),開(kāi)始了。
一,小程序 接入地圖分以下幾步:(將地址轉(zhuǎn)換為坐標(biāo),再將坐標(biāo)傳給微信小程序地圖接口)
????1、申請(qǐng)地圖使用Key(必須)
? ? ? ? 訪問(wèn)騰訊地圖服務(wù)?:?http://lbs.qq.com/qqmap_wx_jssdk/index.html;申請(qǐng)自己的Key;
????2、下載微信小程序JavaScriptSDK,微信小程序JavaScriptSDK v1.0;
????3、 安全域名設(shè)置,需要在微信公眾平臺(tái)添加域名地址https://apis.map.qq.com
????4、小程序代碼? ?(簡(jiǎn)書(shū)格式不支持,需要粘貼后自己調(diào)一下)
// 引入SDK核心類
var QQMapWX = require(' xxx/qqmap-wx-jssdk.js');
Page({
????data: {
? ? ? ? ? ? //小程序調(diào)用地圖的3個(gè)參數(shù)組,下面獲取了地址坐標(biāo)再具體傳入值
? ? ? ? ? ? ?markers: '', polyline: '', controls: '',
? ? ? ? ? ? //用戶輸入的地址
? ?????????? path: '',
????????},
????onLoad: function (options){
? ? ? ? ? var that = this;
? ? ? ? ? var path = options.path;//獲取用戶傳入的地址
????????// 實(shí)例化API核心類
? ? ? ? ? var demo = new QQMapWX({ key: 'XXXXX-XXXXX-G3M4Z-XXXXX-M5PC3-OWBMO' // 必填,換成自己申請(qǐng)的? ? });
????????// 調(diào)用接口,將用戶輸入地址轉(zhuǎn)換為坐標(biāo)(經(jīng)緯度)
????????demo.geocoder({
????????????address: path,? ? ? //傳入地址( ?address: '北京故宮', )
????????????success: function (res) {
????????????????????var path = res.result.location;? //接口調(diào)用成功,取得地址坐標(biāo)!!
? ? ? ? ? ? ? ? ? ? //這里是調(diào)用小程序提供的地圖接口,將上面獲取的坐標(biāo)傳入
????????????????????that.setData({
????????????????????????path:path,
????????????????????????markers: [{ iconPath: "/resources/others.png", id: 0, //地圖位置坐標(biāo) latitude: path.lat, longitude: path.lng, width: 50, height: 50 }],
????????????????????????polyline: [{
????????????????????????????????points: [{ // 紅標(biāo)終點(diǎn)坐標(biāo) latitude: path.lat, longitude: path.lng, }, { //地圖紅線起點(diǎn)坐標(biāo) latitude: path.lat, longitude: path.lng, }], color: "#FF0000DD", width: 2, dottedLine: true }],
????????????????????????????????controls: [{ id: 1, iconPath: '/resources/location.png', position: { left: 0, top: 600 - 50, width: 50, height: 50 }, clickable: true }]
????????????????????????})
? ? ? ? ? ? ? ? ? ? ? ?console.log(res);
????????????????},
????????????????fail: function (res) { // console.log(res); },
????????????????complete: function (res) { // console.log(res); }
????????????});
????????},
????????regionchange(e) { console.log(e.type) },
? ? ? ? markertap(e) { console.log(e.markerId) },
? ? ? ? controltap(e) { console.log(e.controlId) }}
????小程序的調(diào)用成功!!!
二、web端的地圖調(diào)用
????1、申請(qǐng)Key(同小程序)
????2、//GET請(qǐng)求,注意參數(shù)值要進(jìn)行URL編碼 (地址轉(zhuǎn)坐標(biāo))
? ? 3、坐標(biāo)轉(zhuǎn)地址(精準(zhǔn)定位)?GET請(qǐng)求示例,注意參數(shù)值要進(jìn)行URL編碼????
三、若有其他需求,請(qǐng)參考 騰訊地圖網(wǎng)站:http://lbs.qq.com/webservice_v1/index.html;
有什么不對(duì)的,或不懂的,歡迎留言討論
END