当前位置:网站首页>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安全--核心防御机制
- Kubedm deploys kubernetes v1.23.5 cluster
- Qt的右键菜单
- Web security -- core defense mechanism
- Use the kaggle training model and download your own training model
- Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
- Jumping | Blue Bridge Cup
- Openfeign is easy to use
- Makefile Fundamentals
猜你喜欢
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
sqli-labs第2关
Analysis of the use of comparable, comparator and clonable interfaces
OpenFeign 簡單使用
Minecraft module service opening
Comparable,Comparator,Clonable 接口使用剖析
将一串数字顺序后移
IP协议与IP地址
Web security -- Logical ultra vires
TCP/IP—传输层
随机推荐
gocv图片裁剪并展示
Minecraft module service opening
Minecraft空岛服开服
Openfeign facile à utiliser
Synchronize files using unison
Qunhui NAS configuring iSCSI storage
Service de groupe minecraft
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
KubeSphere 虚拟化 KSV 安装体验
zipkin 简单使用
C# 高德地图 根据经纬度获取地址
[untitled]
Dip1000 implicitly tagged with fields
Kubernetes deploys Loki logging system
C# 调用系统声音 嘀~
Hcia - Application Layer
双向链表的实现(双向链表与单向链表的简单区别联系和实现)
Programming ape learning English - imperative programming
Installing Oracle database 19C RAC on Linux
Minecraft插件服开服