


During the development process, we encountered such a need to display products in different regions according to the user's geographical location.
WeChat is used here: the function of obtaining the user's geographical location (reported every 5 seconds or when entering a reply), we convert it into an actual address based on the longitude and latitude pushed by WeChat, which is used here It is Baidu Map API (if you want to use it, apply for Baidu ak first).
PS: This function of WeChat is very unstable, it is unreliable, and it often does not push. . . (Manual positioning was added later, and the Baidu Map Web positioning component is pretty good, not an advertisement! 0.0)
#region 根據(jù)經(jīng)緯度 獲取地址信息 BaiduApi /// <summary> /// 根據(jù)經(jīng)緯度 獲取 地址信息 /// </summary> /// <param name="lat">經(jīng)度</param> /// <param name="lng">緯度</param> /// <returns></returns> public static BaiDuGeoCoding GeoCoder(string lat, string lng) { string url = string.Format(WeiXinConst.Baidu_GeoCoding_ApiUrl, lat, lng); var model = HttpClientHelper.GetResponse<BaiDuGeoCoding>(url); return model; } #endregion
BaiduGeoCoding is an object encapsulated for the corresponding results of the Api:
public class BaiDuGeoCoding { public int Status { get; set; } public Result Result { get; set; } } public class Result { public Location Location { get; set; } public string Formatted_Address { get; set; } public string Business { get; set; } public AddressComponent AddressComponent { get; set; } public string CityCode { get; set; } } public class AddressComponent { /// <summary> /// 省份 /// </summary> public string Province { get; set; } /// <summary> /// 城市名 /// </summary> public string City { get; set; } /// <summary> /// 區(qū)縣名 /// </summary> public string District { get; set; } /// <summary> /// 街道名 /// </summary> public string Street { get; set; } public string Street_number { get; set; } } public class Location { public string Lng { get; set; } public string Lat { get; set; } }
Call:
//需配置 WeiXineConst的BaiduAk string lat = "31.1430"; //經(jīng)度 string lng = "121.2943";// 緯度 var model = WeiXinHelper.GeoCoder(lat, lng);
For more C# WeChat development: For related articles about obtaining addresses based on longitude and latitude, please pay attention to the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)