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

小程序map拖動(dòng)地圖顯示地圖中心標(biāo)記點(diǎn)及經(jīng)緯度方法

這篇具有很好參考價(jià)值的文章主要介紹了小程序map拖動(dòng)地圖顯示地圖中心標(biāo)記點(diǎn)及經(jīng)緯度方法。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

最近做畢設(shè),需要獲取地點(diǎn)坐標(biāo),有了地圖地圖,想想怎么來簡單點(diǎn)。

小程序map拖動(dòng)地圖顯示地圖中心標(biāo)記點(diǎn)及經(jīng)緯度方法

就上網(wǎng)搜了搜(官方有提供地圖選點(diǎn)返回經(jīng)緯度的,但是感覺手指操作不太精準(zhǔn),就想著換一種)

然后自己寫了個(gè)demo(代碼再后面)

大體思路是在map中心放個(gè)很小的圈圈定位用(map中flex垂直水平居中不太行,用了position: absolute的老方法)

然后使用MapContext.getCenterLocation獲取當(dāng)前地圖中心的經(jīng)緯度

再使用MapContext.addMarkers添加 marker(callout中顯示坐標(biāo))

這樣一拖動(dòng)地圖就能顯示地圖中心標(biāo)記點(diǎn)及經(jīng)緯度

小程序map拖動(dòng)地圖顯示地圖中心標(biāo)記點(diǎn)及經(jīng)緯度方法

頑皮一下(addMarkers里忘寫clear: true的后果哈哈哈哈哈哈)

小程序map拖動(dòng)地圖顯示地圖中心標(biāo)記點(diǎn)及經(jīng)緯度方法

代碼:

<!--pages/map/map.wxml-->
<!-- <text>pages/map/map.wxml</text> -->
<view class="view">
    <map 
        class="view_map"
        id="map" 
        subkey="{{subKey}}"
        latitude="{{latitude}}"
        longitude="{{longitude}}"
        scale="{{scale}}"
        show-location="{{showLocation}}"
        enable-poi="{{enable_poi}}"
        markers="{{markers}}"
        bindregionchange="changeCenterLocation"
    >
? ? ? ? <!-- 自己去iconfont隨便下個(gè)圈圈圖案就行 -->
        <image class="img" src="../../circle.png" mode=""/>
    </map>
</view>
// pages/map/map.js
Page({

    /**
     * 頁面的初始數(shù)據(jù)
     */
    data: {
        windowHeight: 1,
        windowWidth: 1,
        lo: 1,
        la: 1,

        subKey: '自己的key',
        latitude: '緯度',
        longitude: '經(jīng)度',
        scale: 16,
        showLocation: true,
        enable_poi: false,
        markers: [],
    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面加載
     */
    onLoad(options) {
        this.mapCtx = wx.createMapContext('map')
? ? ? ? // 沒底圖的就用不上這個(gè)方法
        this.mapCtx.addGroundOverlay({
            id: 0,
            src: "自己的底圖",
            bounds: {
                southwest: { //西南角
                    latitude: 自己寫,
                    longitude: 自己寫,
                },
                northeast: { //東北角
                    latitude: 自己寫,
                    longitude: 自己寫,
                }
            },
            opacity: 0.7,
        })
        var that = this
        wx.getSystemInfo({
            success: function(res){
                that.setData({
                    windowWidth: res.windowWidth,
                    windowHeight: res.windowHeight,
                })
            }
        })
    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
     */
    onReady() {
        
    },

    /**
     * 生命周期函數(shù)--監(jiān)聽頁面顯示
     */
    onShow() {
        this.mapCtx = wx.createMapContext('map',this)
    },

    /**
     * 獲取中心點(diǎn)坐標(biāo)
     */
    changeCenterLocation: function () {
        var that =this
        this.mapCtx.getCenterLocation({
            success: function(res){
                console.log(res.longitude)
                console.log(res.latitude)
                that.setData({
                    lo: res.longitude.toFixed(6),
                    la: res.latitude.toFixed(6),    
                })
                that.addMarkers()
            }
        })   
    },

    /**
     * 添加marker點(diǎn)
     */
    addMarkers: function () {
        this.mapCtx.addMarkers({
            markers:[
                {
                    id: 0,
                    latitude: this.data.la,
                    longitude: this.data.lo,
                    callout:{
                        content: " "+this.data.la+"  "+this.data.lo+" ",
                        display: 'ALWAYS',
                    }
                }
            ],
            clear: true,
        })
        console.log(this.data.markers)
    }
})
/* pages/map/map.wxss */
page {
    height: 100%;
    width: 100%;
}

.view {
    height: 100%;
    width: 100%; 
}

.view_map {
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.img {
    height: 10px;
    width: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}

思路:文章來源地址http://www.zghlxwxcb.cn/news/detail-449712.html

https://blog.csdn.net/ITLISHUANG/article/details/89920332
https://blog.csdn.net/u010481239/article/details/83280946
https://blog.csdn.net/qq_22079371/article/details/89177747

到了這里,關(guān)于小程序map拖動(dòng)地圖顯示地圖中心標(biāo)記點(diǎn)及經(jīng)緯度方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包