Rgooglemaps PlotOnStaticMap Not Scaling with GetMap SCALE parameter

90 views Asked by At

I'm trying to plot some GPS points using Rgooglemaps and to create a plot image larger than 640x640px.

Rgooglemaps GetMap has a SCALE parameter which scales the retrieved google map by up to a factor of two.

Examples: No Scaling & Scaled by 2

Note: The URLs above work intermittently, as Google limits the number of requests allowed without supplying an API key. Just mash F5 until it loads.

If the SCALE value is anything other than 1 in R, when I plot my data with PlotOnStaticMap, none of my coordinates align properly with the map (the map is scaled up, the points are not).

I realise I can scale the output up by avoiding the SCALE and specifying:

png('map.png', height=1280, width=1280)

But this extrapolates the default 640x640px image and the result is blurry.

Is there a way to also proportionally scale up a table of coordinates?

1

There are 1 answers

0
Rocky K On BEST ANSWER

It turns out no scaling of the coordinates was needed, just a few extra parameters:-

What I should've been doing:

# Load Library
library(RgoogleMaps)

# Sample Coordinates
latCoord <- c(40.7079865,40.7062643,40.7043945)
lonCoord <- c(-73.9991936,-73.9969399, -73.9946165)
center <- c(40.707034,-73.992721)

maptile <- GetMap(center=center, zoom=16, maptype='roadmap', extraURL = "&scale=2")

png('testmap.png', height=1280, width=1280)
PlotOnStaticMap(maptile, lat = latCoord, lon = lonCoord, pch = 19, col = "black", add=FALSE, TrueProj = TRUE, cex = 2, size = c(640, 640))

Note the size parameter in the PlotOnStaticMap function needs to be set to 640x640px, even though the output is double that.