Home > WeChat Applet > WeChat Development > WeChat public platform development: map related interface description

WeChat public platform development: map related interface description

高洛峰
Release: 2017-02-27 13:31:49
Original
2189 people have browsed it

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

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

Get the 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

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 in , or directly assigned to Article.PicUrl of ResponseMessageNews.

The corresponding GoogleMap API and SDK have a consistent operating experience.

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


combine SDk, we can use the map interface to perform some functions when the user sends a location message. For example, we process the message in the OnLocationRequest practice of MessageHandler:

/// <summary>
   /// 处理位置请求
   /// </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 = requestMessage.Location_X,
           Y = requestMessage.Location_Y,
           Color = "red",
           Label = "S",
           Size = GoogleMapMarkerSize.Default,
       });
       var mapSize = "480x600";
       var mapUrl = GoogleMapHelper.GetGoogleStaticMap(19 /*requestMessage.Scale*//*微信和GoogleMap的Scale不一致,这里建议使用固定值*/,
                                                       markersList, mapSize);
       responseMessage.Articles.Add(new Article()
       {
           Description = string.Format("您刚才发送了地理位置信息。Location_X:{0},Location_Y:{1},Scale:{2},标签:{3}",
                         requestMessage.Location_X, requestMessage.Location_Y,
                         requestMessage.Scale, requestMessage.Label),
           PicUrl = mapUrl,
           Title = "定位地点周边地图",
           Url = mapUrl
       });
       responseMessage.Articles.Add(new Article()
       {
           Title = "微信公众平台SDK 官网链接",
           Description = "Senparc.Weixin.MK SDK地址",
           PicUrl = "http://weixin.senparc.com/images/logo.jpg",
           Url = "http://weixin.senparc.com"
       });
Copy after login
return responseMessage;<br> }
Copy after login

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

For more WeChat public platform development: map-related interface instructions and related articles, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template