Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverse geocodoing with tidygeocoder and OSM/Nominatim: Get results in latin letters/English? #159

Closed
werkstattcodes opened this issue Feb 4, 2022 · 3 comments

Comments

@werkstattcodes
Copy link

First, many thanks for this wonderful package.

I am reverse geocoding coordinates which pertain to addresses in countries where the Cyrillic alphabet is used. I am using tidygeocoder and OSM/Nominatim as a method. Am I correct, that currently it's not possible to specify the output language/alphabet? How can I modify my request in tidygeocoder to get the results/addresses not in Cyrillic but in Latin letters/in English?

As far as I can tell, the relevant property in the Nominatim/OSM API is accept-language (see here and here). But adding it to a tidygeocoder request seems not to work.

library(tidygeocoder)
library(tidyverse)

df_res <- tibble(
  lat=41.992073,
  long=21.429506
) %>% 
  reverse_geocode(.,
                  lat=lat,
                  long=long,
                  address="address",
                  method="osm") 

The resulting address reads as

Шпаркасе, Македонија, Водно, Центар, Скопје, Општина Центар, Град
Скопје, Скопски СР, 1111, Северна Македонија

Modifying the request to (as suggested here):

tibble(
  lat=41.992073,
  long=21.429506
) %>% 
  reverse_geocode(.,
                  lat=lat,
                  long=long,
                  address="address",
                  method="osm",
                  api_options = list(osm_accept_language="en")
  ) 

leads to an error:

Error: Invalid parameter "osm_accept_language" used in the api_options argument. See ?reverse_geo

The error also occurs when using "osm_accept-language". Many thanks!
PS: I had previously posted the same issue on SO but got no response. So, I hope it's ok to file the "issue" here.

@jessecambon
Copy link
Owner

Hi @werkstattcodes, try using custom_query instead of api_options. That will pass the parameter directly to the Nominatim API (see ?reverse_geo for details).

@werkstattcodes
Copy link
Author

Indeed, this works! Many thanks. I had tried it before, but only now figured out that I have to put accept-language in quotation marks. Again, congrats for this great package.

df_res <- tibble(
  lat=41.992073,
  long=21.429506
) %>% 
  reverse_geocode(.,
                  lat=lat,
                  long=long,
                  address="address",
                  method="osm",
                  custom_query  = list("accept-language"="en-US"))

1 42.0 21.4 Sparkasse, Makedonija, Vodno, Centar, Skopje, Municipality of Centar, City of Skopje,~

@jessecambon
Copy link
Owner

@werkstattcodes awesome, glad it worked. That's interesting that you have to put the parameter name in quotes. I'm guessing that's because it has a hyphen in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants