Google Geolocation API - Use longitude and latitude to get address in textbox?

后端 未结 8 615
有刺的猬
有刺的猬 2021-01-31 05:25

I have noticed a lot of information about how to get your location using Google geolocation looks, based on IP address. But I am wondering if and how I could use this service t

8条回答
  •  余生分开走
    2021-01-31 05:34

    reverse geocoding: get address from latitude and longitude using google maps geocoding api in asp.net

    protected void Page_Load(object sender, EventArgs e)
        {
            GetAddress("53.2734", "-7.77832031");
        }
        private string GetAddress(string latitude, string longitude)
        {
            string locationName = "";
            string url = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=false", latitude, longitude);
            XElement xml = XElement.Load(url);
            if (xml.Element("status").Value == "OK")
            {
                locationName = string.Format("{0}",
                    xml.Element("result").Element("formatted_address").Value);
                Label1.Text = locationName;
            }
            return locationName;
    
        }  
    

提交回复
热议问题