Ⅰ C#語言,從百度地圖反向地理編碼api返回的json數據中提取信息
安裝json.net控制項,並using Newtonsoft.Json.Linq;
這樣就可以獲取想要的tag對應的內容了。
string text = "renderReverse&&renderReverse({\"status\":0,\"result\":{\"location\":{\"lng\":116.32298703399,\"lat\":39.983424051248},\"formatted_address\":\"北京市海淀區中關村大街27號1101-08室\",\"business\":\"中關村,人民大學,蘇州街\",\"addressComponent\":{\"city\":\"北京市\",\"country\":\"中國\",\"direction\":\"附近\",\"distance\":\"7\",\"district\":\"海淀區\",\"province\":\"北京市\",\"street\":\"中關村大街\",\"street_number\":\"27號1101-08室\",\"country_code\":0},\"pois\":[{\"addr\":\"北京北京海淀海淀區中關村大街27號(地鐵海淀黃庄站A1\",\"cp\":\"NavInfo\",\"direction\":\"內\",\"distance\":\"0\",\"name\":\"北京遠景國際公寓(中關村店)\",\"poiType\":\"房地產\",\"point\":{\"x\":116.3229458916,\"y\":39.983610361549},\"tag\":\"房地產\",\"tel\":\"\",\"uid\":\"35a08504cb51b1138733049d\",\"zip\":\"\"},{\"addr\":\"海淀區中關村北大街27號\",\"cp\":\"NavInfo\",\"direction\":\"附近\",\"distance\":\"25\",\"name\":\"中關村大廈\",\"poiType\":\"房地產\",\"point\":{\"x\":116.32285606105,\"y\":39.983568897877},\"tag\":\"房地產;寫字樓\",\"tel\":\"\",\"uid\":\"06d2dffdaef1b7ef88f15d04\",\"zip\":\"\"},{\"addr\":\"中關村大街29\",\"cp\":\"NavInfo\",\"direction\":\"北\",\"distance\":\"62\",\"name\":\"海淀醫院激光整形美容部\",\"poiType\":\"醫療\",\"point\":{\"x\":116.32317046798,\"y\":39.983016046485},\"tag\":\"醫療;專科醫院\",\"tel\":\"\",\"uid\":\"b1c556e81f27cb71b4265502\",\"zip\":\"\"},{\"addr\":\"中關村大街27號中關村大廈1層\",\"cp\":\"NavInfo\",\"direction\":\"附近\",\"distance\":\"1\",\"name\":\"中國人民財產保險中關村營業部\",\"poiType\":\"金融\",\"point\":{\"x\":116.32298182382,\"y\":39.983416864194},\"tag\":\"金融;投資理財\",\"tel\":\"\",\"uid\":\"060f5e53137d20d7081cc779\",\"zip\":\"\"},{\"addr\":\"北京市海淀區\",\"cp\":\"NavInfo\",\"direction\":\"東北\",\"distance\":\"58\",\"name\":\"北京市海淀醫院-輸血科\",\"poiType\":\"醫療\",\"point\":{\"x\":116.322685383,\"y\":39.983092063819},\"tag\":\"醫療;其他\",\"tel\":\"\",\"uid\":\"cf405905b6d82eb9b55f1e89\",\"zip\":\"\"},{\"addr\":\"北京市海淀區中關村大街27號中關村大廈二層\",\"cp\":\"NavInfo\",\"direction\":\"附近\",\"distance\":\"0\",\"name\":\"眉州東坡酒樓(中關村店)\",\"poiType\":\"美食\",\"point\":{\"x\":116.32298182382,\"y\":39.983423774823},\"tag\":\"美食\",\"tel\":\"\",\"uid\":\"2c0bd6c57dbdd3b342ab9a8c\",\"zip\":\"\"},{\"addr\":\"北京市海淀區中關村大街29號(海淀黃庄路口)\",\"cp\":\"NavInfo\",\"direction\":\"東北\",\"distance\":\"223\",\"name\":\"海淀醫院\",\"poiType\":\"醫療\",\"point\":{\"x\":116.32199368776,\"y\":39.982083099537},\"tag\":\"醫療;綜合醫院\",\"tel\":\"\",\"uid\":\"fa01e9371a040053774ff1ca\",\"zip\":\"\"},{\"addr\":\"北京市海淀區中關村大街28號\",\"cp\":\"NavInfo\",\"direction\":\"西北\",\"distance\":\"229\",\"name\":\"海淀劇院\",\"poiType\":\"休閑娛樂\",\"point\":{\"x\":116.32476945179,\"y\":39.982622137118},\"tag\":\"休閑娛樂;電影院\",\"tel\":\"\",\"uid\":\"edd64ce1a6d799913ee231b3\",\"zip\":\"\"},{\"addr\":\"海淀黃庄地鐵站旁\",\"cp\":\"NavInfo\",\"direction\":\"西北\",\"distance\":\"375\",\"name\":\"中發電子市場(中關村大街)\",\"poiType\":\"購物\",\"point\":{\"x\":116.32529945204,\"y\":39.981537146849},\"tag\":\"購物;家電數碼\",\"tel\":\"\",\"uid\":\"69130523db34c811725e8047\",\"zip\":\"\"},{\"addr\":\"北京市海淀區知春路128號\",\"cp\":\"NavInfo\",\"direction\":\"西北\",\"distance\":\"434\",\"name\":\"泛亞大廈\",\"poiType\":\"房地產\",\"point\":{\"x\":116.32600013033,\"y\":39.981516414381},\"tag\":\"房地產;寫字樓\",\"tel\":\"\",\"uid\":\"d24e48ebb9991cc9afee7ade\",\"zip\":\"\"}],\"poiRegions\":[],\"sematic_description\":\"北京遠景國際公寓(中關村店)內0米\",\"cityCode\":131}})";
//只保留Json內容
text = text.Remove(text.Length - 1).Remove(0, 29);
JObject jo = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(text);
//獲取指定TAG的內容
MessageBox.Show(jo["result"]["addressComponent"]["district"].ToString());
Ⅱ 百度地圖API基本使用(一)
在項目需求推動下,我近期研究了網路地圖API。本文將簡要介紹如何開始使用,以供開發者參考。首先,你需要注冊成為網路開發者,創建瀏覽器端應用獲取服務秘鑰(AK)。
1. 登錄開發者平台,點擊"創建應用",選擇與項目相關的應用類型,如Web項目,並設置Referer白名單。完成創建後,你會看到你的AK。
實現網路地圖的關鍵步驟如下:
最後,確保在地圖初始化後使用`setMapStyleV2`方法應用地圖樣式,並注意更新樣式ID的管理。完整的使用流程可參考原文鏈接:[原文鏈接](zhuanlan.hu.com/p/39...),和網站鏈接:[網站鏈接]。