Senparc. Weixin. mp sdk WeChat public platform development tutorial (13): map interface description, senparc. weixin. mp

Source: Internet
Author: User

Senparc. Weixin. mp sdk public platform development tutorial (13): map interface description, senparc. weixin. mp

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 based on distance:Senparc. Weixin. MP. Helpers.GetLatitudeDifference (double km)

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

The generated URL can be directly placed in 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 <GoogleMapMarkers> 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

 

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:

/// <Summary> /// process the location request /// </summary> /// <param name = "requestMessage"> </param> /// <returns> </returns> public override IResponseMessageBase OnLocationRequest (RequestMessageLocation requestMessage) {var responseMessage = ResponseMessageBase. createFromRequestMessage <ResponseMessageNews> (requestMessage); var markersList = new List <GoogleMapMarkers> (); markersList. add (new GoogleMapMarkers () {X = r EquestMessage. 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. format ("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.

 

Series tutorial index: http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html

 

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.