Skip to content

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

@tobadia

Description

@tobadia

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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions