当前位置:网站首页>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.
边栏推荐
- Web security -- Logical ultra vires
- sqli-labs(POST类型注入)
- HCIA—應用層
- Rotating linked list (illustration)
- 文件上传-upload-labs
- Minecraft group service opening
- 图像变换,转置
- Gateway 简单使用
- 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
- Linux安装Oracle Database 19c
猜你喜欢

Minecraft群组服开服

群辉 NAS 配置 iSCSI 存储

链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)

Finishing the interview essentials of secsha system!!!

Linux二进制安装Oracle Database 19c

整理秒杀系统的面试必备!!!

Zipkin is easy to use

Web security -- Logical ultra vires

Minecraft install resource pack

Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
随机推荐
判断是否是数独
汉诺塔问题的求解与分析
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
commands out of sync. did you run multiple statements at once
IP协议与IP地址
Tensorflow2 keras 分类模型
HCIA - application layer
Don't know mock test yet? An article to familiarize you with mock
c语言将字符串中的空格替换成%20
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
Comparable,Comparator,Clonable 接口使用剖析
整理秒杀系统的面试必备!!!
[flask] ORM one-to-one relationship
Kubedm deploys kubernetes v1.23.5 cluster
Network security - summary and thinking of easy-to-use fuzzy tester
Flex layout
HCIA—数据链路层
Call Stack
File upload and download performance test based on the locust framework
OpenShift 部署应用