1、登录或注册高德地图开放平台然后申请应用key(需要认证个人或企业开发者)
2、创建新应用,为新应用添加key,完成第一项后即可看到key管理
3、具体的开发文档、接口入参出参以及结果示例等详见高德地图开放平台官网
4、直接书写具体示例(以区域查询为例)
开发语言:C#
开发工具:visual studio 2019
开发项目类型:控制台程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
private static string GetRegionByURL(string parameters) { string strResult = ""; string url = string.Format("https://restapi.amap.com/v3/config/district?{0}", parameters); try { HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; req.ContentType = "multipart/form-data"; req.Accept = "*/*"; req.UserAgent = ""; req.Timeout = 30000; 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 = ""; Console.WriteLine("异常信息提示:" + ex.Message); Console.ReadLine(); } return strResult; }
|
主函数调用
1 2 3 4 5 6 7 8 9
| const string key = "xxxxxxxxxx"; static void Main(string[] args) { Console.WriteLine("请输入要查询的省份名称,如山东"); string keywords = Console.ReadLine(); string queryRegionResult = GetRegionByURL($"key={key}&subdistrict=2&extensions=base&keywords=" + keywords); Console.WriteLine($"查询{keywords}的结果为:" + queryRegionResult); Console.ReadLine(); }
|
运行结果如下: