WeChat mini-Program map (map) instance details, mini-Program map

Source: Internet
Author: User

Details of map instances, map

Map instance

Here is a small compilation of the map API Information, get the current address, how to implement the instance, you can see.

The map positioning module is implemented today. The simulator certainly cannot obtain the location. The following is the true machine test result.

:



The longitude and latitude are not mentioned. positioning is used. I will directly enter a number here to locate it. But there are many problems.

Scale in is the scaling ratio. This attribute is currently invalid. the team should fix the issue later. after all, we have just started Public Beta. in this way, no matter how I modify the scale, my map is scaled by default. for example.


Rotate in markers is the Rotation Angle of the icon. If you want to parallel to the icon on the screen, set it to 0.

In addition, the covering icon can be modified. You can set the path for iconPath.

The previous code:

<! -- Index. wxml --> <button class = "button" bindtap = "getlocation" style = "margin-top: 30px "markers =" {markers} "> positioning </button> <map longpolling =" {longpolling} "latitude =" {latitude} "markers =" {markers }}" covers = "{covers}" style = "width: 100%; height: 300px; margin-top: 30px "> </map>
// Index. js // obtain the application instance var app = getApp () Page ({data: {latitude: 0, // latitude longpolling: 0, // longitude speed: 0, // speed accuracy: 16, // location accuracy markers: [], covers: [],}, onLoad: function () {}, getlocation: function () {var markers = [{latitude: 31.23, longpolling: 121.47, name: 'pudong new', desc: 'My location'}] var covers = [{latitude: 31.23, longpolling: 121.47, iconPath :'.. /images/car.png ', rotate: 0}] this. setData ({longpolling: 121.47, latitude: 31.23, markers: markers, covers: covers ,})}})

2. wx. getLocation (OBJECT) Get current location API


The red box marks the longitude and latitude, speed, and accuracy.

The coordinates returned by gch02 can be used to open the map directly.

For more information about the api, see the documentation.


3. wx. openLocation (OBJECT) view location

The simplest and most crude is to directly locate the longitude and latitude.

Code:

/Index. js // obtain the application instance var app = getApp () Page ({data: {latitude: 0, // latitude longpolling: 0, // longitude speed: 0, // speed accuracy: 16, // location accuracy markers: [], covers: [],}, onLoad: function () {}, getlocation: function () {wx. getLocation ({type: 'gcj02', success: function (res) {var latitude = res. latitude var longpolling = res. long1_var speed = res. speed var accuracy = res. accuracy console. log ("latitude:" + latitude) console. log ("longpolling:" + longpolling) console. log ("speed:" + speed) console. log ("accuracy:" + accuracy) wx. openLocation ({latitude: latitude, longpolling: longpolling, scale: 28 })}})}})

Real machine test:



Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.