当前位置:网站首页>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.
边栏推荐
- commands out of sync. did you run multiple statements at once
- Qt的右键菜单
- 路由基础—动态路由
- Hcia - Application Layer
- gocv边界填充
- kubernetes部署loki日志系统
- C language custom type enumeration, Union (clever use of enumeration, calculation of union size)
- Kubedm deploys kubernetes v1.23.5 cluster
- c语言将字符串中的空格替换成%20
- kubeadm部署kubernetes v1.23.5集群
猜你喜欢

HCIA—数据链路层

Web security -- Logical ultra vires

TCP/IP—传输层

C language replaces spaces in strings with%20

Installing Oracle database 19C RAC on Linux

Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)

Service de groupe minecraft

kubeadm部署kubernetes v1.23.5集群

群辉 NAS 配置 iSCSI 存储

Analysis of the use of comparable, comparator and clonable interfaces
随机推荐
File upload Labs
旋转链表(图解说明)
一个经典约瑟夫问题的分析与解答
Installing Oracle database 19C for Linux
[blackmail virus data recovery] suffix Crylock blackmail virus
Tcp/ip - transport layer
Qunhui NAS configuring iSCSI storage
Luogu greedy part of the backpack line segment covers the queue to receive water
Judge whether it is Sudoku
Kubernetes deploys Loki logging system
OpenShift构建镜像
Qt的拖动事件
The best blog to explain the basics of compilation (share)
KubeSphere 虚拟化 KSV 安装体验
Minecraft install resource pack
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
Function ‘ngram‘ is not defined
Minecraft模组服开服
Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
Sqli labs (post type injection)