shows a static map which is a png file.

If I do have a coordinate which lies between the coordinates of this static map file, then how should I plot that point on this map (which is basically a png)?


I would be doing it offline. Can't use the maps API. Will save that map as a PNG, then I have to plot the points.


Check the API here: https://developers.google.com/maps/documentation/staticmaps/#Markers


http://maps.googleapis.com/maps/api/staticmap?center=Williamsburg,Brooklyn,NY&zoom=13&size=400x400& markers=color:blue%7Clabel:S%7C11211%7C11206%7C11222&sensor=true_or_false

  • Sorry, my fault. I should have mentioned that I would be doing it offline. Can't use the maps API. – Aquarius_Girl Jul 13 '12 at 9:09
  • @AnishaKaul According to s 10(1)(3), what you're trying to do is against the TOS. The answer i've suggested is the only way you can legally make it happen. Otherwise, I'd suggest using OSM. – nagytech Jul 13 '12 at 9:27
  • The TOS says "except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation if you do so temporarily, securely, and in a manner that does not permit use of the Content outside of the Service;" Is that still illegal? – Aquarius_Girl Jul 13 '12 at 9:30
  • @AnishaKaul Prefetching / Caching is not the issue. The subsection above that 10(1)(3)(i) explicitly states that the modification of tiles (ie. creating derivative works) is not permitted. I would be happy to help you otherwise, possibly with the use of GD or ImageMagik. Open Street Map would most likely permit you to do this if you followed the proper attribution methods. I'm not sure, however, how much OSM data is available for where your project is. – nagytech Jul 13 '12 at 9:41
  • Okay, I didn't read that. Sorry. BTW, now you mentioned ImageMagik, I found on search a library named "R": cran.r-project.org/web/packages/RgoogleMaps/vignettes/… that may not be legal but is that practical ? – Aquarius_Girl Jul 13 '12 at 10:16

Another alternative (avoiding the TOS issue) would be to use OSM (as suggested by Geoist). That would be really simple, because you can easily work a position / offset position to a pixel offset into the image using the formula given at http://wiki.openstreetmap.org/wiki/Zoom_levels

You could still use PIL as I suggested in my other (proposed) answer.


Use gdal to build the right Transform (conversion from coordinate to pixel), and then add the icon to the pixel point.

http://www.gdal.org/ogr/osr_tutorial.html tells you how to build the transformation.

You can add the icon using many methods, including something like PIL. http://www.pythonware.com/library/pil/handbook/image.htm, look for the paste() method.

  • For that you would have to know the exact tile level, and image scale which you aren't necessarily provided unless you specify it explicitly, and explicitly specifying it will not give you the best field of view. Not to mention, you left out how to actually add the icon to the pixel point. – nagytech Jul 13 '12 at 9:47
  • The tile level is in the URL. – BradHards Jul 13 '12 at 10:31
  • Indeed it is, because the user specified it. Read my comment more carefully. – nagytech Jul 13 '12 at 11:04
  • I don't understand your issue. You'll always have either a position and zoom level or geo-extent. Am I missing something? – BradHards Jul 13 '12 at 22:41

The way to do this in R is as follows: http://cran.r-project.org/web/packages/RgoogleMaps/RgoogleMaps.pdf

library (RgoogleMaps)
png (filename = "plotted.png", width=480, height=480)

lat    = c(40.702147,40.718217,40.711614)
lon    = c(-74.012318,-74.015794,-73.998284)
center = c(mean(lat), mean(lon))
zoom <- min (MaxZoom (range(lat), range(lon)))

MyMap <- GetMap (center   = center, 
                 zoom     = zoom,     
                 markers  = '&40.702147,-74.015794,blues%7C40.711614,-74.012318,greeng%7C40.718217,-73.998284,redc', 
                 destfile = 'original.png');

tmp <- PlotOnStaticMap (MyMap, 
                        lat = c(40.702147, 40.711614, 40.718217), 
                        lon = c(-74.015794,-74.012318,-73.998284), 
                        cex = 1.5, 
                        pch = 20, 
                        col = c('red', 'blue', 'green'), 
                        add = F)


To compile the above R code in C++, R has provided a package named RInside:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.