/// <summary>
/// 高德地图调用帮助类
/// 更多详情请参考 高德api
/// </summary>
public class GaodeHelper
{
//高德平台申请的秘钥
public static string SecretKey = "申请的秘钥"; /// <summary>
/// 获取经纬度
/// </summary>
/// <param name="address"></param>
/// <param name="city"></param>
/// <returns></returns>
public static string GetGeocode(string address,string city)
{
string geocodeUrl = "http://restapi.amap.com/v3/geocode/geo?address={Address}&city={City}&output=json&key={SecretKey}"
.Replace("{SecretKey}", SecretKey)
.Replace("{Address}", address)
.Replace("{City}", city); string geocode = WebClientDownloadInfoToString(geocodeUrl);
geocode = GetLatitudeAndLongitude(geocode);
return geocode;
} /// <summary>
/// 获取城市之间的距离
/// </summary>
/// <param name="begin"></param>
/// <param name="beginCity"></param>
/// <param name="end"></param>
/// <param name="endCity"></param>
/// <returns></returns>
public static string GetDistance(string begin,string beginCity, string end, string endCity)
{
string origin = GetGeocode(begin,beginCity);
string destination = GetGeocode(end, endCity);
string driveUri = "http://restapi.amap.com/v3/direction/driving?key={SecretKey}&origin={Origin}&destination={Destination}"
.Replace("{SecretKey}", SecretKey)
.Replace("{Origin}", origin)
.Replace("{Destination}", destination); string result= WebClientDownloadInfo(driveUri);
//var gd = Newtonsoft.Json.JsonConvert.DeserializeObject<GaodeReturn>(result);
return result;
} private static string WebClientDownloadInfo(string uri)
{
string result = string.Empty;
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/xml;charset=UTF-8";
result = wc.DownloadString(uri);
}
return result;
} /// <summary>
/// 模拟请求
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
private static string WebClientDownloadInfoToString(string uri)
{
string result = string.Empty;
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/xml;charset=UTF-8";
result = wc.DownloadString(uri);
}
return result;
} /// <summary>
/// 解析返回的经纬度信息
/// </summary>
/// <param name="GeocodeJsonFormat"></param>
/// <returns></returns>
private static string GetLatitudeAndLongitude(string GeocodeJsonFormat)
{
JObject o = JObject.Parse(GeocodeJsonFormat);
string geocodes = (string)o["geocodes"][]["location"];
return geocodes;
}
}

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. linux编程之消息队列

    消息队列是内核地址空间中的内部链表,通过linux内核在各个进程之间传递内容,消息顺序地发送到消息队列中,并且以几种不同的方式 从队列中获取,每个消息队列可以用IPC标识符唯一的进行标识,内核中的消息 ...

  2. Keil MDK 5.14 仿真时System Viewer菜单显示空白和Peripherals菜单无外设寄存器

    keil mdk5.14新建工程进行仿真时,进入Debug环境发现System Viewer菜单显示空白,Peripherals菜单没有外设寄存器.如图1和图2所示.打开Oprons for Targ ...

  3. 自己动手一步步安装Linux系统

    自己动手一步步安装Linux系统 http://502245466.blog.51cto.com/7559397/1291910/

  4. 设计模式之笔记--原型模式(Prototype)

    原型模式(Prototype) 定义 原型模式(Prototype),用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 类图 描述 提供一个克隆自身的接口--Clone方法. 应用场景 ...

  5. 实现点击页面其他地方,隐藏div(vue)

    方法一: 通过监听事件 document.addEventListener('click',function(e){ if(e.target.className!='usermessage'){ th ...

  6. 2:django models Making queries

    这是后面要用到的类 class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextFie ...

  7. linux命令(35):head命令

    1.命令格式: head [参数]... [文件]... 2.命令功能: head 用来显示档案的开头至标准输出中,默认head命令打印其相应文件的开头10行. 3.命令参数: -q 隐藏文件名 -v ...

  8. C语言写随机数

    #include <stdio.h> #include <stdlib.h> #include <time.h> ; unsigned int rand0(); v ...

  9. <一>dubbo框架学前原理介绍

    alibaba有好几个分布式框架,主要有:进行远程调用(类似于RMI的这种远程调用)的(dubbo.hsf),jms消息服务(napoli.notify),KV数据库(tair)等.这个框架/工具/产 ...

  10. poj 1692(动态规划)

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