Getting the user's city from its coordinates via OpenStreetMap Nominatim by reverse geocoding

64 Views Asked by At

I have a telegram bot that receives the user's geolocation and must send the city in response, how can this be done?

I tried to write the code, but it does not throw an error " Response status code does not indicate success"

 static async void reverseGeocoding(string latitude, string longitude)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.DefaultConnectionLimit = 9999;
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

            var url = @$"http://nominatim.openstreetmap.org/reverse?format=xml&lat={latitude}&lon={longitude}&zoom=18&addressdetails=1"; // ПОМЕНЯТЬ НА HTTPS
            string responseString = await client.GetStringAsync(url);
            Console.WriteLine(responseString);
            locationUser = responseString;
            return;

        }
0

There are 0 best solutions below