C# 高德地图调用帮助类 GaodeHelper
- /// <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的更多相关文章
- objective-c高德地图时时定位
这篇随笔是对上一遍servlet接口的实现. 一.项目集成高德地图 应为我这个项目使用了cocopods这个第三方库管理工具,所以只需要很简单的步骤,就能将高德地图集成到项目中,如果你没使用过这工具, ...
- Java 通过地址获取经纬度 - 高德地图
一.添加依赖 <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-v ...
- 【原创】web端高德地图javascript API的调用
关于第三放地图的使用,腾讯.百度.高德 具体怎么选择看你自己怎么选择了. 高德地图开放平台:http://lbs.amap.com/ 本次使用的是高德的javascript API http://lb ...
- java调用高德地图api实现通过ip定位访问者的城市
所需东西:高德地图的key 注意:这个key是 web服务的key 和js的key不是一个key(若没有则自行创建,创建教程在文末) 高德地图的api文档:https://lbs.amap.com/ ...
- Android编程 高德地图 AMapLocationClientOption 类中 setWifiActiveScan过时
高德地图中 定位包中有以下方法: AMapLocationClientOption 类中 setWifiActiveScan 过时 isWifiActiveScan public boole ...
- web端高德地图javascript API的调用
[转载https://www.cnblogs.com/zimuzimu/p/6202244.html]web端高德地图javascript API的调用 关于第三放地图的使用,腾讯.百度.高德 具体怎 ...
- vue 调用高德地图
一. vue-amap,一个基于 Vue 2.x 和高德地图的地图组件 https://elemefe.github.io/vue-amap/#/ 这个就不细说了,按照其文档,就能够安装下来. 二. ...
- 高德地图web端笔记;发送http请求的工具类
1.查询所有电子围栏 package com.skjd.util; import java.io.BufferedReader; import java.io.InputStream; import ...
- Android 编程 AMapLocationClientOption 类中的 setNeedAddress 方法用处 (高德地图 com.amap.api.location.AMapLocationClientOption 中的类)
最近在用高德地图来写Android App, 其中有一些 方法是不太理解的,这里写一下 对 高德地图 com.amap.api.location.AMapLocationClientOption ...
随机推荐
- [Leetcode Week15] Add Two Numbers
Add Two Numbers 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/add-two-numbers/description/ Descrip ...
- 3:django models Making queries 高级进阶--聚合运算
在前一遍文章django models Making queries里面我们提到了django常用的一些检索数据库的内容, 下面我们来看一下更为高级的检索聚合运算 这是我们要用到的模型 class A ...
- 关于Free的override不能省略的问题,切记,虚方法是可以被覆盖的方法。
- ActiveMQ基于JMS的pub/sub传播机制
原文地址:[ActiveMQ实战]基于JMS的pub/sub传播机制 发布订阅模型 就像订阅报纸,我们可以选择一份或者多份报纸.比如:北京日报.人民日报.这些报纸就相当于发布订阅模型中的topic.如 ...
- LeetCode解题报告—— Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = ...
- poj 1692(动态规划)
Crossed Matchings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2711 Accepted: 1759 ...
- 【转】Jmeter-----函数引用和函数重定向
详见内文
- [水煮 ASP.NET Web API2 方法论](12-2)管理 OData 路由
问题 如何控制 OData 路由 解决方案 为了注册路由,可以使用 HttpConfigurationExtension 类中 MapODataServiceRoute 的扩展方法.对于单一路由这样 ...
- grunt 自定义任务实现js文件的混淆及加密
//自定义任务 module.exports = function (grunt) { // 项目配置 var http = require('http'); var qs = require('qu ...
- C/C++ 基础知识
C/C++ 基础知识 C 语言优秀学习网站 [C Programming Language] C 语言的注释 单行注释 /* comment goes here */ // comment goes ...