Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the map-related interfaces in the development of Wechat public platform

Shulou Source: shulou.com Published: 2022-06-03 16:13:39 11月14日 Update

This article mainly introduces the Wechat public platform development of map-related interfaces, the article is very detailed, has a certain reference value, interested friends must read it!

In order to facilitate the development of LBS applications, SDK encapsulates common calculation formulas and the map interfaces of Baidu and Google.

Common calculations:

Used to calculate the straight line distance between two coordinate points: Senparc.Weixin.MP.Helpers.Distance (double N1, double E1, double N2, double e2)

Get the dimension difference according to distance: Senparc.Weixin.MP.Helpers.GetLatitudeDifference (double km)

Longitude difference based on distance: Senparc.Weixin.MP.Helpers.GetLongitudeDifference (double km)

Baidu API class: Senparc.Weixin.MP.Helpers.BaiduMapHelper

Generate Baidu static map URL:BaiduMapHelper.GetBaiduStaticMap (double lng, double lat, int scale, int zoom, IList markersList, int width = 400, int height = 300)

The final generated address is as follows:

Http://maps.googleapis.com/maps/api/staticmap?center=&zoom=13&size=640x640&maptype=roadmap&format=jpg&sensor=false&language=zh&&markers=color:red%7Clabel:O%7C31.285774,120.59761&markers=color:blue%7Clabel:T%7C31.289774,120.59791

The generated URL can be placed directly into the

Or assign a value directly to the Article.PicUrl of ResponseMessageNews.

Consistent operation experience has been done in the corresponding GoogleMap API,SDK.

GoogleMap API class: Senparc.Weixin.MP.Helpers.GoogleMapHelper

Generate Baidu static map URL:GoogleMapHelper.GetGoogleStaticMap (int scale, IList markersList, string size = "640x640")

The generated address is as follows:

Http://maps.googleapis.com/maps/api/staticmap?center=&zoom=&size=640x640&maptype=roadmap&format=jpg&sensor=false&language=zh&&markers=color:red%7Clabel:O%7C31.285774,120.59761&markers=color:blue%7Clabel:T%7C31.289774,120.59791

Combined with SDk, we can use the map API to do some functions when users send location messages. For example, we deal with messages in MessageHandler's OnLocationRequest practice:

/ processing location requests / public override IResponseMessageBase OnLocationRequest (RequestMessageLocation requestMessage) {var responseMessage = ResponseMessageBase.CreateFromRequestMessage (requestMessage); var markersList = new List () MarkersList.Add (new GoogleMapMarkers () {X = requestMessage.Location_X, Y = requestMessage.Location_Y, Color = "red", Label = "S", Size = GoogleMapMarkerSize.Default,}); var mapSize = "480x600" Var mapUrl = GoogleMapHelper.GetGoogleStaticMap (19 / * the Scale of requestMessage.Scale*//* Wechat is inconsistent with that of GoogleMap. It is recommended to use a fixed value * /, markersList, mapSize); responseMessage.Articles.Add (new Article () {Description = string.Format) ("you just sent geolocation information. Location_X: {0}, Location_Y: {1}, Scale: {2}, tag: {3} ", requestMessage.Location_X, requestMessage.Location_Y, requestMessage.Scale, requestMessage.Label), PicUrl = mapUrl, Title =" location surrounding map ", Url = mapUrl}) ResponseMessage.Articles.Add (new Article () {Title = "Wechat public platform SDK official website link", Description = "Senparc.Weixin.MK SDK address", PicUrl = "https://cache.yisu.com/upload/information/20201208/260/13380.jpg", Url =" http://weixin.senparc.com"}); return responseMessage

}

In the actual development process, in addition to outputting location information, we can also retrieve the nearest point according to the user's current location, output it in Articles, and calculate the distance.

The above is all the contents of the article "what are the map-related interfaces in the development of Wechat public platform". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Map location generation interface development public platform address consistency information content common use message user article static processing output value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Xiaomi Shulou Information Docker