1. /// <summary>
  2. /// 高德地图调用帮助类
  3. /// 更多详情请参考 高德api
  4. /// </summary>
  5. public class GaodeHelper
  6. {
  7. //高德平台申请的秘钥
  8. public static string SecretKey = "申请的秘钥";
  9.  
  10. /// <summary>
  11. /// 获取经纬度
  12. /// </summary>
  13. /// <param name="address"></param>
  14. /// <param name="city"></param>
  15. /// <returns></returns>
  16. public static string GetGeocode(string address,string city)
  17. {
  18. string geocodeUrl = "http://restapi.amap.com/v3/geocode/geo?address={Address}&city={City}&output=json&key={SecretKey}"
  19. .Replace("{SecretKey}", SecretKey)
  20. .Replace("{Address}", address)
  21. .Replace("{City}", city);
  22.  
  23. string geocode = WebClientDownloadInfoToString(geocodeUrl);
  24. geocode = GetLatitudeAndLongitude(geocode);
  25. return geocode;
  26. }
  27.  
  28. /// <summary>
  29. /// 获取城市之间的距离
  30. /// </summary>
  31. /// <param name="begin"></param>
  32. /// <param name="beginCity"></param>
  33. /// <param name="end"></param>
  34. /// <param name="endCity"></param>
  35. /// <returns></returns>
  36. public static string GetDistance(string begin,string beginCity, string end, string endCity)
  37. {
  38. string origin = GetGeocode(begin,beginCity);
  39. string destination = GetGeocode(end, endCity);
  40. string driveUri = "http://restapi.amap.com/v3/direction/driving?key={SecretKey}&origin={Origin}&destination={Destination}"
  41. .Replace("{SecretKey}", SecretKey)
  42. .Replace("{Origin}", origin)
  43. .Replace("{Destination}", destination);
  44.  
  45. string result= WebClientDownloadInfo(driveUri);
  46. //var gd = Newtonsoft.Json.JsonConvert.DeserializeObject<GaodeReturn>(result);
  47. return result;
  48. }
  49.  
  50. private static string WebClientDownloadInfo(string uri)
  51. {
  52. string result = string.Empty;
  53. using (WebClient wc = new WebClient())
  54. {
  55. wc.Headers[HttpRequestHeader.ContentType] = "application/xml;charset=UTF-8";
  56. result = wc.DownloadString(uri);
  57. }
  58. return result;
  59. }
  60.  
  61. /// <summary>
  62. /// 模拟请求
  63. /// </summary>
  64. /// <param name="uri"></param>
  65. /// <returns></returns>
  66. private static string WebClientDownloadInfoToString(string uri)
  67. {
  68. string result = string.Empty;
  69. using (WebClient wc = new WebClient())
  70. {
  71. wc.Headers[HttpRequestHeader.ContentType] = "application/xml;charset=UTF-8";
  72. result = wc.DownloadString(uri);
  73. }
  74. return result;
  75. }
  76.  
  77. /// <summary>
  78. /// 解析返回的经纬度信息
  79. /// </summary>
  80. /// <param name="GeocodeJsonFormat"></param>
  81. /// <returns></returns>
  82. private static string GetLatitudeAndLongitude(string GeocodeJsonFormat)
  83. {
  84. JObject o = JObject.Parse(GeocodeJsonFormat);
  85. string geocodes = (string)o["geocodes"][]["location"];
  86. return geocodes;
  87. }
  88. }

C# 高德地图调用帮助类 GaodeHelper的更多相关文章

  1. objective-c高德地图时时定位

    这篇随笔是对上一遍servlet接口的实现. 一.项目集成高德地图 应为我这个项目使用了cocopods这个第三方库管理工具,所以只需要很简单的步骤,就能将高德地图集成到项目中,如果你没使用过这工具, ...

  2. Java 通过地址获取经纬度 - 高德地图

    一.添加依赖 <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-v ...

  3. 【原创】web端高德地图javascript API的调用

    关于第三放地图的使用,腾讯.百度.高德 具体怎么选择看你自己怎么选择了. 高德地图开放平台:http://lbs.amap.com/ 本次使用的是高德的javascript API http://lb ...

  4. java调用高德地图api实现通过ip定位访问者的城市

    所需东西:高德地图的key 注意:这个key是 web服务的key  和js的key不是一个key(若没有则自行创建,创建教程在文末) 高德地图的api文档:https://lbs.amap.com/ ...

  5. Android编程 高德地图 AMapLocationClientOption 类中 setWifiActiveScan过时

    高德地图中   定位包中有以下方法: AMapLocationClientOption  类中  setWifiActiveScan  过时 isWifiActiveScan public boole ...

  6. web端高德地图javascript API的调用

    [转载https://www.cnblogs.com/zimuzimu/p/6202244.html]web端高德地图javascript API的调用 关于第三放地图的使用,腾讯.百度.高德 具体怎 ...

  7. vue 调用高德地图

    一. vue-amap,一个基于 Vue 2.x 和高德地图的地图组件 https://elemefe.github.io/vue-amap/#/ 这个就不细说了,按照其文档,就能够安装下来. 二. ...

  8. 高德地图web端笔记;发送http请求的工具类

    1.查询所有电子围栏 package com.skjd.util; import java.io.BufferedReader; import java.io.InputStream; import ...

  9. Android 编程 AMapLocationClientOption 类中的 setNeedAddress 方法用处 (高德地图 com.amap.api.location.AMapLocationClientOption 中的类)

    最近在用高德地图来写Android App, 其中有一些 方法是不太理解的,这里写一下 对  高德地图  com.amap.api.location.AMapLocationClientOption ...

随机推荐

  1. [Leetcode Week15] Add Two Numbers

    Add Two Numbers 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/add-two-numbers/description/ Descrip ...

  2. 3:django models Making queries 高级进阶--聚合运算

    在前一遍文章django models Making queries里面我们提到了django常用的一些检索数据库的内容, 下面我们来看一下更为高级的检索聚合运算 这是我们要用到的模型 class A ...

  3. 关于Free的override不能省略的问题,切记,虚方法是可以被覆盖的方法。

     

  4. ActiveMQ基于JMS的pub/sub传播机制

    原文地址:[ActiveMQ实战]基于JMS的pub/sub传播机制 发布订阅模型 就像订阅报纸,我们可以选择一份或者多份报纸.比如:北京日报.人民日报.这些报纸就相当于发布订阅模型中的topic.如 ...

  5. LeetCode解题报告—— Interleaving String

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = ...

  6. poj 1692(动态规划)

    Crossed Matchings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2711   Accepted: 1759 ...

  7. 【转】Jmeter-----函数引用和函数重定向

    详见内文

  8. [水煮 ASP.NET Web API2 方法论](12-2)管理 OData 路由

    问题 如何控制 OData 路由 解决方案 为了注册路由,可以使用  HttpConfigurationExtension 类中 MapODataServiceRoute 的扩展方法.对于单一路由这样 ...

  9. grunt 自定义任务实现js文件的混淆及加密

    //自定义任务 module.exports = function (grunt) { // 项目配置 var http = require('http'); var qs = require('qu ...

  10. C/C++ 基础知识

    C/C++ 基础知识 C 语言优秀学习网站 [C Programming Language] C 语言的注释 单行注释 /* comment goes here */ // comment goes ...