WeChat public platform development: map related interfaces

Source: Internet
Author: User
To facilitate the development of LBS applications, the SDK encapsulates frequently used computing formulas and map interfaces of Baidu and Google. To facilitate the development of LBS applications, the SDK encapsulates frequently used computing formulas and map interfaces of Baidu and Google.

Common computing:

Used to calculate the linear Distance between two coordinate points: Senparc. Weixin. MP. Helpers. Distance (double n1, double e1, double n2, double e2)

Obtain the dimension difference by distance: Senparc. Weixin. MP. Helpers. GetLatitudeDifference (double km)

Obtain the longitude difference by 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 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 % 7 Clabel: O % 7C31. 285774,120.59761 & markers = color: blue % 7 Clabel: T % 7C31. 289774,120.59791


The generated URL can be directly put into the file or directly assigned to the Article. PicUrl of ResponseMessageNews.

The corresponding GoogleMap API provides a consistent operation experience in the 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 % 7 Clabel: O % 7C31. 285774,120.59761 & markers = color: blue % 7 Clabel: T % 7C31. 289774,120.59791


In combination with the SDk, we can use the map interface for some functions when the user sends a location message. for example, we process the message in the OnLocationRequest practice of MessageHandler:

////// Process the location request /////////
 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/* requestMessage. scale * // * is different from GoogleMap's Scale. Here we recommend using a fixed value */, markersList, mapSize); responseMessage. articles. add (new Article () {Description = string. fo Rmat ("You just sent the location 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 = "official public Platform SDK website", Description = "Senparc. weixin. mk sdk address ", PicUrl =" http://weixin.senparc.com /Images/logo.jpg ", Url =" http://weixin.senparc.com "});
  
 
return responseMessage;
}

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

For more public platform development: For more information about map-related interfaces, see PHP!

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.