国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序之移動地圖獲取坐標(biāo)和位置信息

這篇具有很好參考價值的文章主要介紹了微信小程序之移動地圖獲取坐標(biāo)和位置信息。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、實現(xiàn)效果演示

其實就是在小程序上移動,然后實時的獲取地址中心點的坐標(biāo)信息,然后通過坐標(biāo)數(shù)據(jù)信息獲取地址信息的過程;

小程序map搜索內(nèi)容并返回搜索目的地的坐標(biāo),怎么實現(xiàn),微信小程序,微信小程序,小程序

?二、前端代碼實現(xiàn)

<view?class="mapshow">

??<map?class="mapUI"?id="myMap"?scale="13"?bindmarkertap="bindmarkertap"?data-index="{{index}}"?show-location?markers="{{markers}}"?latitude="{{latitude}}"?longitude="{{longitude}}"?bindregiοnchange="bindregionchange"?show-location></map>

</view>

<view?class="resultInforTip"?style="margin-left:?25rpx;">

??<view>

????注:您可移動地圖,選擇企業(yè)的地址獲取坐標(biāo)信息

??</view>

</view>

<view?class="tipInforyinhuan">

??<view?class="tipInforTop">

????<view?class="inputTip">

??????企業(yè)地址信息

????</view>

????<view?class="zoomtop">

??????<view?class="loginInput">

????????<view?class="loginTip"?style="display:?flex;flex-direction:?row;margin-top:?5rpx;">

??????????<view>

????????????企業(yè)地址

??????????</view>

??????????<view?style="color:?#f00;font-weight:?bold;font-size:?25rpx;text-align:?center;align-items:?center;">

????????????(*請將以下位置信息修改為企業(yè)的詳細(xì)地址)

??????????</view>

????????</view>

????????<input?type="text"?class="inputInfor"?placeholder="請輸入地址信息"?bindinput="passwordInput"?value="{{myaddress}}"?/>

????????<view?class="lineView"></view>

????????<view?class="loginTip"?style="margin-top:?25rpx;">企業(yè)經(jīng)緯度</view>

????????<view?class="inputInfor">

??????????<view?class="totalInfor">{{mylatitude}},{{mylongitude}}</view>

????????</view>

????????<view?class="lineView"></view>

??????</view>

????</view>

??</view>

</view>

<view?class="btninfor"?style="padding-bottom:?30rpx;">

??<view?class="subButton"?hover-class='view-box-btn-hover'?hover-start-time='5'?bindtap="loginListener">

????確認(rèn)提交位置信息

??</view>

</view>

說明:

1:這塊的代碼其實就是上面是一個map地圖控件,下面是一個顯示的view控件而已;

2:bindregionchange這個屬性就是監(jiān)聽位置的變化方法

三、js邏輯實現(xiàn)

1:實時監(jiān)聽地圖的位置變化

?//?視野發(fā)生變化時觸發(fā)

??bindregionchange:?function?(e)?{

????console.log("實時獲取地圖位置坐標(biāo)數(shù)據(jù)信息",?e.detail.centerLocation);??? ? ?

???//以下代碼對坐標(biāo)數(shù)據(jù)進行地址轉(zhuǎn)換

????var?qqMapApi?=?'https://apis.map.qq.com/ws/geocoder/v1/'?+?"?location="?+?e.detail.centerLocation.latitude?+?','?+

??????e.detail.centerLocation.longitude?+?"&key="您申請的key"&get_poi=1";

????this.sendRequest(qqMapApi);

???//以下下代碼是給地圖添加一個marker數(shù)據(jù)信息

??let?mapAddress?=?[];

????mapAddress.push({

??????id:?1001,

??????//?id:?this.data.companyAddress[i].id,

??????latitude:?e.detail.centerLocation.latitude,

??????longitude:?e.detail.centerLocation.longitude,

??????iconPath:?'/pages/image/markerimage.png',

??????width:?'34px',

??????height:?'34px',

??????content:?"111",

????});

????this.setData({

??????mylatitude:?e.detail.centerLocation.latitude,

??????mylongitude:?e.detail.centerLocation.longitude,

??????markers:?mapAddress,

????})

????if?(e.causedBy?==?"scale"?||?e.causedBy?==?"drag")?{

??????//?獲取地圖位置改變后的中心點經(jīng)緯度以及獲取中心點附近的位置信息

??????//?this.getCenterLocationFunc();

????}?else?{

??????console.log("其余事件不執(zhí)行邏輯");

????}

??},文章來源地址http://www.zghlxwxcb.cn/news/detail-776711.html

2:對坐標(biāo)數(shù)據(jù)進行地址轉(zhuǎn)換

????var?qqMapApi?=?'https://apis.map.qq.com/ws/geocoder/v1/'?+?"?location="?+?e.detail.centerLocation.latitude?+?','?+

??????e.detail.centerLocation.longitude?+?"&key="您申請的key"&get_poi=1";

????this.sendRequest(qqMapApi);

3:轉(zhuǎn)換以及保存地址數(shù)據(jù)

??sendRequest:?function?(qqMapApi)?{

????const?that?=?this

????wx.request({

??????url:?qqMapApi,

??????header:?{

????????'Content-Type':?'application/json'

??????},

??????data:?{},

??????method:?'GET',

??????success:?(res)?=>?{

????????console.log(res.data.result.address)

????????that.setData({

??????????myaddress:?res.data.result.address,

????????});

??????}

????})

??},

到了這里,關(guān)于微信小程序之移動地圖獲取坐標(biāo)和位置信息的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包