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

How to view the docker run startup parameter command (recommended)

Use runlike to view the docker run startup parame...

The difference and usage of LocalStorage and SessionStorage in vue

Table of contents What is LocalStorage What is Se...

Today I will share some rare but useful JS techniques

1. Back button Use history.back() to create a bro...

How to set PATH environment variable in Linux system (3 methods)

1. In Windows system, many software installations...

Why can't I see the access interface for Docker Tomcat?

Question: Is the origin server unable to find a r...

Chrome monitors cookie changes and assigns values

The following code introduces Chrome's monito...

Analysis of the principle of using PDO to prevent SQL injection

Preface This article uses pdo's preprocessing...

An Incomplete Guide to JavaScript Toolchain

Table of contents Overview Static type checking C...

Solution to find all child rows for a given parent row in MySQL

Preface Note: The test database version is MySQL ...

Analysis of Difficulties in Hot Standby of MySQL Database

I have previously introduced to you the configura...

A brief discussion on MySQL event planning tasks

1. Check whether event is enabled show variables ...

Linux uses dual network card bond and screwdriver interface

What is bond NIC bond is a technology that is com...