网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網(wǎng)

微信小程序位置API

發(fā)布時間:2018-04-20 11:00 所屬欄目:小程序開發(fā)教程

作者:BloodyMandoo    原文:http://blog.csdn.net/bloodymandoo/article/details/72885460

1、獲取位置

wx.getLocation(OBJECT) 
獲取當(dāng)前的地理位置、速度。當(dāng)用戶離開小程序后,此接口無法調(diào)用;當(dāng)用戶點擊“顯示在聊天頂部”時,此接口可繼續(xù)調(diào)用。

 

				
  1. [javascript] view plain copy
  2. var that=this;
  3. wx.getLocation({
  4. type: 'wgs84',
  5. success: function (res) {
  6. var latitude = res.latitude
  7. var longitude = res.longitude
  8. var speed = res.speed
  9. var accuracy = res.accuracy
  10. var altitude = res.altitude
  11. var verticalAccuracy = res.verticalAccuracy
  12. var horizontalAccuracy = res.horizontalAccuracy
  13. that.setData({
  14. longitude: longitude,
  15. latitude: latitude,
  16. speed: speed,
  17. accuracy: accuracy,
  18. altitude: altitude,
  19. verticalAccuracy: verticalAccuracy,
  20. horizontalAccuracy: horizontalAccuracy
  21. })
  22. }
  23. })

wx.chooseLocation(OBJECT)  打開地圖選擇位置

 

2、查看位置

wx.openLocation(OBJECT)  ? 使用微信內(nèi)置地圖查看位置

 

  1. wx.getLocation({
  2. type: 'gcj02', //返回可以用于wx.openLocation的經(jīng)緯度
  3. success: function(res) {
  4. var latitude = res.latitude
  5. var longitude = res.longitude
  6. wx.openLocation({
  7. latitude: latitude,
  8. longitude: longitude,
  9. scale: 28
  10. })
  11. }
  12. })
 

3、地圖組件控制

wx.createMapContext(mapId)  創(chuàng)建并返回 map 上下文 mapContext 對象  mapContext  mapContext 通過 mapId 跟一個 組件綁定,通過它可以操作對應(yīng)的 組件。  mapContext 對象的方法列表

方法 參數(shù) 說明 最低版本  getCenterLocation OBJECT 獲取當(dāng)前地圖中心的經(jīng)緯度,返回的是 gcj02 坐標系,可以用于 wx.openLocation  moveToLocation 無 將地圖中心移動到當(dāng)前定位點,需要配合map組件的show-location使用  translateMarker OBJECT 平移marker,帶動畫 1.2.0  includePoints OBJECT 縮放視野展示所有經(jīng)緯度 1.2.0  getCenterLocation 的 OBJECT 參數(shù)列表

參數(shù) 類型 必填 說明  success Function 否 接口調(diào)用成功的回調(diào)函數(shù) ,res = { longitude: "經(jīng)度", latitude: "緯度"}  fail Function 否 接口調(diào)用失敗的回調(diào)函數(shù)  complete Function 否 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)  translateMarker 的 OBJECT 參數(shù)列表

參數(shù) 類型 必填 說明  markerId Number 是 指定marker  destination Object 是 指定marker移動到的目標點  autoRotate Boolean 是 移動過程中是否自動旋轉(zhuǎn)marker  duration Number 否 動畫持續(xù)時長,默認值1000ms,平移與旋轉(zhuǎn)分別計算  animationEnd Function 否 動畫結(jié)束回調(diào)函數(shù)  includePoints 的 OBJECT 參數(shù)列表

參數(shù) 類型 必填 說明  points Array 是 要顯示在可視區(qū)域內(nèi)的坐標點列表,[{latitude, longitude}]  padding Array 否 坐標點形成的矩形邊緣到地圖邊緣的距離,單位像素。格式為[上,右,下,左],安卓上只能識別數(shù)組第一項,上下左右的padding一致。開發(fā)者工具暫不支持padding參數(shù)。

 

  1. <!-- map.wxml -->
  2. <map id="myMap" show-location />
  3.  
  4. <button type="primary" bindtap="getCenterLocation">獲取位置</button>
  5. <button type="primary" bindtap="moveToLocation">移動位置</button>
  6. <button type="primary" bindtap="translateMarker">移動標注</button>
  7. <button type="primary" bindtap="includePoints">縮放視野展示所有經(jīng)緯度</button>
 

  1. // map.js
  2. Page({
  3. onReady: function (e) {
  4. // 使用 wx.createMapContext 獲取 map 上下文
  5. this.mapCtx = wx.createMapContext('myMap')
  6. },
  7. getCenterLocation: function () {
  8. this.mapCtx.getCenterLocation({
  9. success: function(res){
  10. console.log(res.longitude)
  11. console.log(res.latitude)
  12. }
  13. })
  14. },
  15. moveToLocation: function () {
  16. this.mapCtx.moveToLocation()
  17. },
  18. translateMarker: function() {
  19. this.mapCtx.translateMarker({
  20. markerId: 0,
  21. autoRotate: true,
  22. duration: 1000,
  23. destination: {
  24. latitude:23.10229,
  25. longitude:113.3345211,
  26. },
  27. animationEnd() {
  28. console.log('animation end')
  29. }
  30. })
  31. },
  32. includePoints: function() {
  33. this.mapCtx.includePoints({
  34. padding: [10],
  35. points: [{
  36. latitude:23.10229,
  37. longitude:113.3345211,
  38. }, {
  39. latitude:23.00229,
  40. longitude:113.3345211,
  41. }]
  42. })
  43. }
  44. })


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23775.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×