当前位置:网站首页>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.
边栏推荐
猜你喜欢

Minecraft群组服开服

Sqli labs Level 2

Solid principle: explanation and examples

Installing Oracle database 19C for Linux

Web security -- core defense mechanism

Data asset management function

Don't know mock test yet? An article to familiarize you with mock

Kubesphere virtualization KSV installation experience

commands out of sync. did you run multiple statements at once

IP protocol and IP address
随机推荐
C#钉钉开发:取得所有员工通讯录和发送工作通知
Openshift deployment application
sqli-labs第2关
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
kubeadm部署kubernetes v1.23.5集群
使用wireshark抓取Tcp三次握手
Realization of basic function of sequence table
HCIA - data link layer
Finishing the interview essentials of secsha system!!!
kubernetes部署loki日志系统
Minecraft install resource pack
sqli-labs(POST类型注入)
C# 百度地图,高德地图,Google地图(GPS) 经纬度转换
Qunhui NAS configuring iSCSI storage
一、Qt的核心类QObject
将一串数字顺序后移
commands out of sync. did you run multiple statements at once
k8s入门:Helm 构建 MySQL
Use Wireshark to grab TCP three handshakes
File upload and download performance test based on the locust framework