This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

nominatim encoding

0

Hi

I'm consuming the web service of nominatim to reverse geocoding in my .NET Application but the xml I get in my String variable is not the same as I see in the browser and accents the spoils me and makes me strange characters when using coordinates in asia

Any idea???

Thanks

asked 19 Mar '14, 15:02

kintela's gravatar image

kintela
11112
accept rate: 0%

edited 19 Mar '14, 16:07

SomeoneElse's gravatar image

SomeoneElse ♦
36.9k71370866

Could you give some examples (of the code that fails, the data that you're expecting, and the data that you get back)?

(19 Mar '14, 15:11) SomeoneElse ♦

Of course. For example this request http://nominatim.openstreetmap.org/reverse?format=xml&lat=50,9683209807591&lon=2,57099452814137&zoom=18&addressdetails=1

The result: D 70, farm, Bettencourt-Rivière, Amiens, Somme, Picardía, Francia metropolitana, 80890, Francia

But in my C# code

public string Inversa(double latitud, double longitud) { WebClient webClient = new WebClient();

        try
        {

            string cadena = "http://nominatim.openstreetmap.org/reverse?format=xml&lat=" + Convert.ToString(latitud) + "&lon=" + Convert.ToString(longitud) + "&zoom=18&addressdetails=1";

            string result = webClient.DownloadString(cadena);

            return result;
        }
        catch (Exception e)
        {
            throw e;
        }
    }

I get: D 70, farm, Bettencourt-Rivière, Amiens, Somme, Picardie, France métropolitaine, 80890, France

Thanks

(19 Mar '14, 15:17) kintela

One Answer:

3

Nominatim always returns its results in UTF-8 encoding. It looks like you are trying to interpret the result using some windows encoding. According to this stackoverflow question you need to set webClient.Encoding = System.Text.Encoding.UTF8 to enforce the correct encoding.

answered 19 Mar '14, 15:40

lonvia's gravatar image

lonvia
6.2k25789
accept rate: 40%

Hi.

This must be done before using the web client.DownloadString

webClient.Encoding = Encoding.UTF8;

Thanks

(19 Mar '14, 15:58) kintela

Source code available on GitHub .