dkahle / dkahle/ggmap

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

Open
#358 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
778
Forks
234
PR merge metrics
No merged PRs in 30d

Description

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`: https://github.com/dkahle/ggmap/blob/4cdb1fb9b1c2c800f87acbc63dbc5896347f27be/R/get_map.R#L189

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 !

Contributor guide

No contributing guide indexed for this repository

Research direction

Open R/get_map.R at the zoom calculation around line 189 and reproduce the issue with the provided bounding box and a Google API key. Verify the zoom selection against both latitude and longitude extents; done means the fetched map covers the complete requested range for the example and other providers.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.