Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the current position, longitude and latitude and map display in WeChat Mini Programs

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to obtain the current location longitude and latitude and map display in WeChat Mini Programs". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to obtain the current location longitude and latitude and map display in WeChat Mini Programs" can help you solve the problem.

The main body of WeChat Mini Programs includes:

The new page needs to be configured in app.json:

"pages": ["pages/index/index", "pages/location/location", "pages/logs/logs"]

By calling bindtap in the view layer to match the method in the logic layer-- to achieve the page jump:

View layer

Get the user's current location

Logical layer

LocationViewTap: function () {wx.navigateTo ({url:'.. / location/location'})}

By calling bindtap in the view layer to match the method in the logic layer-- implement the method call:

View layer

View map selection location

Logical layer

MapViewTap:function () {wx.getLocation ({type: 'gcj02', / / returns latitude and longitude that can be used for wx.openLocation success: function (res) {console.log (res) wx.openLocation ({latitude: res.latitude, longitude: res.longitude, scale: 28})}

Three interfaces for map location:

(1) wx.getLocation (OBJECT) to obtain the current geographic location and speed

Success return parameters:

Latitude latitude, floating point number, range is-90 to 90, negative number indicates south latitude longitude longitude, floating point number, range is-180 to 180, negative number indicates west longitude speed speed, floating point number, accuracy of unit m/saccuracy position

(2) wx.openLocation (OBJECT) uses Wechat built-in map to view location

OBJECT parameter description:

The parameter type is required to indicate that latitudeFloat is latitude, with a range of-90mm 90. A negative number indicates that south latitude longitudeFloat is longitude, with a range of-180cm. A negative number indicates the negative scaling ratio of west longitude scaleINT, with a range of 5mm 18. The default is 18nameString negative name addressString No address. Details of successFunction No API call successful callback function failFunction No API call failed callback function completeFunction No API call end callback function (successful or failed will be executed)

(3) wx.chooseLocation (OBJECT) Open Map selection location

Success return parameters:

Name location name address detailed address latitude latitude, floating point number, range is-90mm 90, negative number indicates south latitude longitude longitude, floating point number, range is-180mm 180, negative number indicates west longitude

Realize the effect

Use getLocation to obtain the longitude and latitude coordinates of the current location, and openLocation opens Wechat built-in map to view

Use chooseLocation to select the location and display the longitude and latitude of the location information in real time.

Note:

(1) the map parameter information obtained by getLocation () is only two.

The parameters returned using chooselocation are as follows:

(2) this.setData modifies the value in json

The json data in the logical layer can be displayed through the WXML file {{json}}:

This is the end of the introduction about "how to get the longitude, latitude and map display of the current location in WeChat Mini Programs". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report