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

Auto calculation of zoom level does not always cover lat/lon range #358

Open
tobadia opened this issue Jan 31, 2024 · 0 comments
Open

Auto calculation of zoom level does not always cover lat/lon range #358

tobadia opened this issue Jan 31, 2024 · 0 comments

Comments

@tobadia
Copy link

tobadia commented Jan 31, 2024

Hi,

Upon toying around with ggmap, I realized in some instances the zoom level that is calculated is erroneous so that the returned map does not cover the complete range of latitude and longitude when it is provided as a bounding box. This was tested on Google Maps with "hybrid" maps but the behavior should be identical for all map providers.
The blame is tu put here, where the max should rather be min:

zoom <- max(zoomlon, zoomlat)

Replicable exemple (you'll need your own Google API key)

# Global variables, API key...
MAP_PROVIDER                  <- "google"
GOOGLE_API_KEY              <- ""

if (MAP_PROVIDER == "google") {
  register_google(key = GOOGLE_API_KEY)
}

# Example failing
gps_range <- c("left" = 46.00803, 
"bottom" = -19.62127, 
"right" = 46.11314, 
"top" = -19.35588)

# Get and plot map
plot_map <- get_map(location = gps_range, 
              source   = MAP_PROVIDER, 
              maptype  = MAP_TYPE)

With that example, zoomlon is calculated at 11 and zoomlat at 13. The map that is fetched at a max of these two (13) has coordinates ranging latitude -19.540 through -19.440, and longitude 46.000 through 46.125. The latitude does not cover the expected extent.

Changing the max to min solves the issue.

Thanks for considering this !

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

1 participant