高德地图API
最近在学习高德地图api接口调用,需要获取场景的一些信息,最重要的是获取轮廓图
需要的接口基本都有 轮廓图的接口没有
获取基本信息
https://lbs.amap.com/api/webservice/summary/
查找到自己需要的接口
并调用
public static string GetDataByWhere(string city,string type,int offset,int page, string keywords=””,int timeout = 10000)
{
string url = “https://restapi.amap.com/v3/place/text?key={0}&keywords={1}&types={2}&city={3}&children=1&offset={4}&page={5}&extensions=all”;
url = string.Format(url, key, keywords, type, city, offset, page);
return GetLocationByURL(url, timeout);
}
/// <summary>
/// 根据URL获取地址
/// </summary>
/// <param name=”url”>Get方法的URL</param>
/// <param name=”timeout”>超时时间默认10秒</param>
/// <returns></returns>
private static string GetLocationByURL(string url, int timeout = 10000)
{
string strResult = “”;
try
{
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
req.ContentType = “multipart/form-data”;
req.Accept = “*/*”;
//req.UserAgent = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)”;
req.UserAgent = “”;
req.Timeout = timeout;
req.Method = “GET”;
req.KeepAlive = true;
HttpWebResponse response = req.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
strResult = sr.ReadToEnd();
}
}
catch (Exception ex)
{
strResult = “”;
}
return strResult;
}
就这样
轮廓接口
public static string GetLuokuoData(string poiid, string querytype = “IDQ”, int timeout = 10000)
{
// https://www.amap.com/service/poiInfo?query_type=TQUERY&pagesize=20&pagenum=1&qii=true&cluster_state=5&need_utd=true&utd_sceneid=1000&div=PC1000&addr_poi_merge=true&is_classify=true&zoom=18&city=530100&geoobj=102.786068%7C25.053343%7C102.792128%7C25.054913&keywords=%E8%8A%B1%E4%B9%8B%E5%9F%8E
// string url = “https://gaode.com/service/poiInfo?query_type=IDQ&pagesize=20&pagenum=1&qii=true&cluster_state=5&need_utd=true&utd_sceneid=1000&div=PC1000&addr_poi_merge=true&is_classify=true&zoom=11&id=B000A88EBH”;
string url = “https://gaode.com/service/poiInfo?query_type={0}&pagesize=5000&pagenum=1&qii=true&cluster_state=5&need_utd=true&utd_sceneid=1000&div=PC1000&addr_poi_merge=true&is_classify=true&zoom=11&id={1}”;
url = string.Format(url, querytype, poiid);
return GetLocationByURL(url, timeout);
}
综上即可获取一个场景下面的信息和轮廓数组之后解析
解析
/// <summary>
/// 获取当前的数据
/// </summary>
/// <param name=”pricent”>省份</param>
/// <param name=”type”>类型</param>
/// <param name=”keywork”>关键字</param>
public void GetData(string cityname,string type,string keywork)
{
string json = “”;
json = AmapUtil.GetDataByWhere(cityname, type, 50,1, keywork);
JObject o = JObject.Parse(json);
IList<JObject> allDrives = o[“pois”].Select(t => (JObject)t).ToList();
foreach (JObject j in allDrives)
{
// object a = j;
string id = j[“id”].ToString();
string name = j[“name”].ToString();
string types = j[“type”].ToString();
string address = j[“address”].ToString();
string location = j[“location”].ToString();
string pcode = j[“pcode”].ToString();
string pname = j[“pname”].ToString();
string cityID = j[“citycode”].ToString();
string citynames = j[“cityname”].ToString();
string adcode = j[“adcode”].ToString();
string adname = j[“adname”].ToString();
Console.WriteLine(j.ToString());
string[] local = location.Split(\’,\’);
string json1 = AmapUtil.GetLuokuoData(id);
JObject o1 = JObject.Parse(json1);
string dd1 = o1[“data”].ToString();
JObject od1 = JObject.Parse(dd1);
IList<JToken> s1 = od1[“poi_list”].ToList();
foreach (JToken jtt in s1)
{
string df = jtt[“domain_list”].ToString();
IList<JToken> s2 = jtt[“domain_list”].ToList();
foreach (JToken jt in s2)
{
string names = jt[“name”].ToString();
if (names == “aoi”)
{
string value = jt[“value”].ToString();
string[] a = value.Split(\’_\’);
string truevalue = “”;
for (int i = 0; i < a.Length; i++)
{
truevalue += “[” + a[i] + “],”;
}
if (!string.IsNullOrEmpty(truevalue))
{
truevalue = truevalue.Substring(0, truevalue.Length – 1);
}
truevalue = “[[” + truevalue + “]]”;
}
}
}
}
}