2
votes

I am using Nominatim reverse geocoding service to get address from latitude and longitude. Then, store the result in Mysql Database. The coding is as fiddle below:

http://jsfiddle.net/GWL7A/171/

The address returned is in the local language such as in the example is in Chinese. And the data stored is not readable as:

"麒麟山新æ‘, 惠æ¥åŽ¿, 广东, 中åŽäººæ°‘共和国/China"
  1. Is that possible to make the address returned in English.
  2. If that's not possible, how to store the data into database so that when retrieve it and show in web UI, it returned to Chinese words? It must not be limited to only Chinese word since it might be Afghanistan, Thailand, Vietnam or some other country's addresses.

Thank you.

2
Well, the fiddle shows me 麒麟山新村, Huilai Xian, Guangdong, People's Republic of China which is over 50% English. :-) - wallyk
What language are you using to store the result in the database? Given that the fiddle is client-side JavaScript, are you then sending the result over to the server, or are you using Node.js or something? Either way this is almost surely a character encoding/interpretation problem of some sort. - AKX
@wallyk but i will need it purely in English or otherwise show up "麒麟山新村, Huilai Xian, Guangdong, People's Republic of China". Now it just show up "麒麟山新æ‘, æƒ æ¥åŽ¿, 广东, 中åŽäººæ°‘共和国/China" in web UI after I inserted the address into database - Fei Hap Lee
@AKX the fidle is actually to let u all test and get the result. My method is calling the api in PHP and it returned result in json format. I decoded and get the address from it and then store the result into database. FYI, the result shown in fiddle is the same as what i get from json decode. - Fei Hap Lee

2 Answers

1
votes

The object in question is not yet internationalized in OSM, so nominatim can only give you its original name (which is in Chinese). If you really need the name “in English”/in latin script, you probably have to do the transcription by yourself. I guess one can find some han-pinyin transcription library out there…

btw: make sure to use the correct charset when adding the strings to your database. OSM is using utf-8.

0
votes

You can use &accept-language=es;q=0.8,de;q=0.4,en;q=0.2 at the end of the API:

https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=33.6321882&lon=72.8587481&accept-language=es;q=0.8,de;q=0.4,en;q=0.2

Which give you the result address returned in English.

The Above URL giving the results:

{"place_id":138192283,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"way","osm_id":263218431,"lat":"33.6328352161182","lon":"72.8584455708076","place_rank":26,"category":"highway","type":"residential","importance":0.1,"addresstype":"road","name":null,"display_name":"E 18, F-17, Dhok Minda, Islamabad, Pakistán","address":{"neighbourhood":"E 18","suburb":"F-17","village":"Dhok Minda","state":"Islamabad","country":"Pakistán","country_code":"pk"},"boundingbox":["33.6324874","33.6342918","72.8577017","72.8614997"]}

Without using &accept-language=es;q=0.8,de;q=0.4,en;q=0.2:

The JSON response is coming in URDU:

{"place_id":138192283,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"way","osm_id":263218431,"lat":"33.6328352161182","lon":"72.8584455708076","place_rank":26,"category":"highway","type":"residential","importance":0.1,"addresstype":"road","name":null,"display_name":"E 18, F-17, Dhok Minda, وفاقی دارالحکومت اسلام آباد, Pakistan","address":{"neighbourhood":"E 18","suburb":"F-17","village":"Dhok Minda","state":"وفاقی دارالحکومت اسلام آباد","country":"Pakistan","country_code":"pk"},"boundingbox":["33.6324874","33.6342918","72.8577017","72.8614997"]}

for the URL:

https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=33.6321882&lon=72.8587481