当前位置:网站首页>C Gaode map obtains the address according to longitude and latitude
C Gaode map obtains the address according to longitude and latitude
2022-07-02 08:46:00 【Qingshan blog】
using System;
using System.IO;
using System.Net;
using System.Text;
namespace PhotoHelper
{
public class AmapUtil
{
private const string Key = "3ee6df6847015dec899aa46032226fa0";
/// <summary>
/// Get the address according to latitude and longitude
/// </summary>
/// <param name="lngLatStr"> String of longitude and latitude for example :"113.692100,34.752853"</param>
/// <param name="timeout"> Timeout defaults to 10 second </param>
/// <returns> Failure to return "" </returns>
public static string GetLocationByLngLat(string lngLatStr, int timeout = 10000)
{
var url = $"http://restapi.amap.com/v3/geocode/regeo?key={Key}&location={lngLatStr}";
return GetLocationByUrl(url, timeout);
}
/// <summary>
/// Get the address according to latitude and longitude
/// </summary>
/// <param name="lng"> longitude for example :113.692100</param>
/// <param name="lat"> dimension for example :34.752853</param>
/// <param name="timeout"> Timeout defaults to 10 second </param>
/// <returns> Failure to return "" </returns>
public static string GetLocationByLngLat(double lng, double lat, int timeout = 10000)
{
var url = $"http://restapi.amap.com/v3/geocode/regeo?key={Key}&location={lng},{lat}";
return GetLocationByUrl(url, timeout);
}
/// <summary>
/// according to URL Get address
/// </summary>
/// <param name="url">Get Methodical URL</param>
/// <param name="timeout"> Timeout defaults to 10 second </param>
/// <returns></returns>
private static string GetLocationByUrl(string url, int timeout = 10000)
{
var s = "";
try
{
if (WebRequest.Create(url) is HttpWebRequest req)
{
req.ContentType = "multipart/form-data";
req.Accept = "*/*";
req.UserAgent = "";
req.Timeout = timeout;
req.Method = "GET";
req.KeepAlive = true;
if (req.GetResponse() is HttpWebResponse response)
using (var sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
s = sr.ReadToEnd();
return s;
}
}
}
catch (Exception ex)
{
s = ex.ToString();
}
return s;
}
}
}Be careful : In this paper, the Key It's a personal application I applied for , There are times and frequency limits , Please replace the formal environment with your own Key.
边栏推荐
- ARP及ARP欺骗
- Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
- Sqli labs (post type injection)
- Rotating linked list (illustration)
- Gateway 简单使用
- Kubernetes deploys Loki logging system
- Use the numbers 5, 5, 5, 1 to perform four operations. Each number should be used only once, and the operation result value is required to be 24
- Qt的connect函数和disconnect函数
- 选择排序和插入排序
- 旋转链表(图解说明)
猜你喜欢

C language replaces spaces in strings with%20

路由基础—动态路由

Zipkin is easy to use

Rotating linked list (illustration)

Application of kotlin - higher order function

ARP及ARP欺骗
![[blackmail virus data recovery] suffix Rook3 blackmail virus](/img/46/debc848d17767d021f3f41924cccfe.jpg)
[blackmail virus data recovery] suffix Rook3 blackmail virus

Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it

HCIA—数据链路层
![[blackmail virus data recovery] suffix Hydra blackmail virus](/img/27/f44334cf98229d0f8b33c70a878ca8.jpg)
[blackmail virus data recovery] suffix Hydra blackmail virus
随机推荐
Sentinel 简单使用
IP协议与IP地址
Openshift container platform community okd 4.10.0 deployment
c语言将字符串中的空格替换成%20
DWORD ptr[]
Tensorflow2 keras 分类模型
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
Tensorflow2 keras classification model
k8s入门:Helm 构建 MySQL
Qt的拖动事件
Makefile Fundamentals
OpenShift构建镜像
First week of JS study
HCIA—数据链路层
ICMP协议
HCIA - data link layer
Use Wireshark to grab TCP three handshakes
Installing Oracle database 19C RAC on Linux
Learning C
Nacos download, start and configure MySQL database