您好,登錄后才能下訂單哦!
這篇文章主要介紹微信公眾平臺(tái)開發(fā)中地圖相關(guān)接口有哪些,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
為了方便大家開發(fā)LBS應(yīng)用,SDK對(duì)常用計(jì)算公式,以及百度和谷歌的地圖接口做了封裝。
常用計(jì)算:
用于計(jì)算2個(gè)坐標(biāo)點(diǎn)之間的直線距離:Senparc.Weixin.MP.Helpers.Distance(double n1, double e1, double n2, double e2)
根據(jù)距離獲取維度差:Senparc.Weixin.MP.Helpers.GetLatitudeDifference(double km)
根據(jù)距離獲取經(jīng)度差:Senparc.Weixin.MP.Helpers.GetLongitudeDifference(double km)
百度API類:Senparc.Weixin.MP.Helpers.BaiduMapHelper
生成百度靜態(tài)地圖URL:BaiduMapHelper.GetBaiduStaticMap(double lng, double lat, int scale, int zoom, IList<BaiduMarkers> markersList, int width = 400, int height = 300)
最后生成的地址如下:
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
生成的URL可以直接放到<img>中,或者直接賦值在ResponseMessageNews的Article.PicUrl。
對(duì)應(yīng)的GoogleMap API,SDK中做了一致的操作體驗(yàn)。
GoogleMap API類:Senparc.Weixin.MP.Helpers.GoogleMapHelper
生成百度靜態(tài)地圖URL:GoogleMapHelper.GetGoogleStaticMap(int scale, IList<GoogleMapMarkers> markersList, string size = "640x640")
生成的地址如下:
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
結(jié)合SDk,我們可以在用戶發(fā)送位置消息過來的時(shí)候,使用地圖接口做一些功能,例如我們?cè)贛essageHandler的OnLocationRequest實(shí)踐中對(duì)消息進(jìn)行處理:
/// <summary> /// 處理位置請(qǐng)求 /// </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("您剛才發(fā)送了地理位置信息。Location_X:{0},Location_Y:{1},Scale:{2},標(biāo)簽:{3}", requestMessage.Location_X, requestMessage.Location_Y, requestMessage.Scale, requestMessage.Label), PicUrl = mapUrl, Title = "定位地點(diǎn)周邊地圖", Url = mapUrl }); responseMessage.Articles.Add(new Article() { Title = "微信公眾平臺(tái)SDK 官網(wǎng)鏈接", Description = "Senparc.Weixin.MK SDK地址", PicUrl = "https://cache.yisu.com/upload/information/20201208/260/13380.jpg", Url = "http://weixin.senparc.com" });
return responseMessage;<br> }
實(shí)際的開發(fā)過程中,除了輸出位置的信息,我們還可以根據(jù)用戶的當(dāng)前位置,檢索就近的點(diǎn),在Articles中輸出,并計(jì)算出距離。
以上是“微信公眾平臺(tái)開發(fā)中地圖相關(guān)接口有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。