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