当前位置:网站首页>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.
边栏推荐
猜你喜欢
OpenFeign 簡單使用
Flex layout
Linux安装Oracle Database 19c
Sentinel easy to use
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
Nacos 下载启动、配置 MySQL 数据库
Application of kotlin - higher order function
commands out of sync. did you run multiple statements at once
sqli-labs第1关
Minecraft install resource pack
随机推荐
c语言自定义类型枚举,联合(枚举的巧妙使用,联合体大小的计算)
Flex layout
Judge whether it is Sudoku
Makefile基本原理
Zipkin is easy to use
Realization of basic function of sequence table
Loadbalancer dynamically refreshes Nacos server
Rotating linked list (illustration)
C language replaces spaces in strings with%20
用数字 5,5,5,1 ,进行四则运算,每个数字当且仅当用一次,要求运算结果值为 24
Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)
File upload and download performance test based on the locust framework
Qt——如何在QWidget中设置阴影效果
c语言自定义类型——结构体,位段(匿名结构体,结构体的自引用,结构体的内存对齐)
OpenShift构建镜像
Googlenet network explanation and model building
Sqli labs Level 2
文件上传-upload-labs
群辉 NAS 配置 iSCSI 存储
sqli-labs第8关(布尔盲注)