Detailed explanation of how to use WeChat mini program map

Detailed explanation of how to use WeChat mini program map

This article example shares the specific implementation code used by the WeChat applet map for your reference. The specific content is as follows

The following code is the main code snippet

<!-- Map section -->
  <!-- enable-traffic Display traffic conditions -->
  <view class="map_container">
   <map id='customerMap' class="map" :longitude='longitude' :latitude='latitude' :scale='scale'
    :markers='markers' :controls="controls" show-location
    @markertap="markertap" @updated="updatedmap" @controltap='bindcontroltap'></map>
</view>
data(){
  return {
      latitude:23.140962248,
      longitude:113.305301124,
      scale:12,
      markers:[ {id: '',
     latitude: 23.140962248,
     longitude: 113.305301124,
     iconPath: '../static/select-dw.png', //Current location icon path width: 25,
     height: 39,
     },
                    {
                    latitude: 23.129742,
     longitude: 113.26754,
     iconPath: '../static/mark.png', //Customer icon path width: 28,
     height: 28,
     label: {
      content: 'Zhan Junjun',
      textAlign: 'center',
      fontSize: 12
        }
                    }]  
 
  }
 
},
onReady() {
 this.mapCtx = wx.createMapContext('customerMap')
},
methods:{
 
    // Click on the marker point markertap(e) {
    let { markerId } = e.detail;
    let item = this.markers.find(v => v.id === markerId);
    console.log('item', item)
    uni.openLocation({
     latitude: Number(item.latitude),
     longitude: Number(item.longitude),
     name: item.label.content,
     address: item.address,
     success: function() {
      console.log('success');
     }
    });
   },
    // When the map is loaded, trigger updatedmap() {
    this.mapUpdated = true;
    console.log('execution')
    this.includePoints(); //All customers are displayed in the view},
    // Make the marker point visible in the map includePoints() {
    const that = this
    const points = [{
     latitude: that.latitude,
     longitude: that.longitude
    }];
    this.markers.forEach(item => {
     const obi = {
      latitude: item.latitude,
      longitude: item.longitude
     }
     points.push(obi)
    })
    this.mapCtx.includePoints({
     padding: [80, 50, 80, 50],
     points
    })
   },
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • WeChat applet map positioning simple example
  • WeChat applet map (map) example detailed explanation
  • How to implement map navigation function in WeChat applet
  • Detailed explanation and implementation steps of using Tencent Map SDK in WeChat Mini Program
  • WeChat Mini Program Amap SDK Detailed Explanation and Simple Examples (Source Code Download)
  • WeChat applet map detailed explanation and simple example
  • WeChat applet development map implementation tutorial
  • WeChat applet: Get the current location latitude and longitude and map display details
  • WeChat Mini Program Tutorial: Detailed Example of Local Image Upload (leancloud)
  • How to get longitude and latitude by clicking on the WeChat applet map component

<<:  Example of using MRG_MyISAM (MERGE) to implement query after partitioning in MySQL

>>:  8 powerful techniques for HTML web page creation

Recommend

mysql show simple operation example

This article describes the mysql show operation w...

How to deploy FastDFS in Docker

Install fastdfs on Docker Mount directory -v /e/f...

Implementation of Docker deployment of Tomcat and Web applications

1. Download docker online yum install -y epel-rel...

Who is a User Experience Designer?

Scary, isn't it! Translation in the picture: ...

Specific implementation methods of MySQL table sharding and partitioning

Vertical table Vertical table splitting means spl...

How to create a Pod in Kubernetes

Table of contents How to create a Pod? kubectl to...

React implements the sample code of Radio component

This article aims to use the clearest structure t...

How to install pip package in Linux

1. Download the pip installation package accordin...

Sample code for html list box, text field, and file field

Drop-down box, text field, file field The upper p...

Analysis and solutions to problems encountered in the use of label tags

I used the label tag when I was doing something re...

Thoughts on copy_{to, from}_user() in the Linux kernel

Table of contents 1. What is copy_{to,from}_user(...