search
HomeWeChat AppletWeChat DevelopmentWeChat public platform development: map related interface description

WeChat public platform development: map related interface description

Feb 27, 2017 pm 01:31 PM
Micro-channel public platform

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 WeChat public platform development: map related interface description, 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"
       });
return responseMessage;<br> }

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!


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function