Code covered by the BSD License  

Highlights from
plot_google_map

5.0

5.0 | 11 ratings Rate this file 114 Downloads (last 30 days) File Size: 5.32 KB File ID: #27627
image thumbnail

plot_google_map

by Zohar Bar-Yehuda

 

16 May 2010

Plot a google map on the background of the current figure using the Static Google Maps API.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

plot_google_map.m uses the Google Maps API to plot a map in the background of the current figure.

It assumes the coordinates of the current figure are in the WGS84 datum, and uses a conversion code to convert and project the image from the coordinate system used by Google into WGS84 coordinates.

The zoom level of the map is automatically determined to cover the entire area of the figure. Additionally, it has the option to auto-refresh the map upon zooming in the figure, revealing more details as one zooms in.

The following code produces the screenshot:

lat = [48.8708 51.5188 41.9260 40.4312 52.523 37.982];
lon = [2.4131 -0.1300 12.4951 -3.6788 13.415 23.715];
plot(lon,lat,'.r','MarkerSize',20)
plot_google_map('maptype','roadmap')

Known Issues:
1) The resolution of the maps downloaded via the API is limited to 640 pixels. Since a portion of the downloaded map is usually outside the current axis zoom, this results in a slightly pixelated rendering.
2) The static maps API is limited to 1000 requests per day. If you use this function a lot, consider disabling the auto-refresh upon zoom option.

Note:
The Static Maps V2 API no longer requires an API key.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
get_google_map

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
24 Jun 2010 Jan Vidar  
23 Sep 2010 Gary  
09 Oct 2010 danish zubairi

made my life easier

15 Nov 2010 Aaron Holtzman  
22 Dec 2010 Seb Biass

Wow, that is cool, thanks!
Question: I am using a contourf plot and adding the map behind. So I set the colormap and the transparency for the contourf, but all colors change when I plot the background map. Any idea where that could come from?

Thanks!

27 Dec 2010 Zohar Bar-Yehuda

Seb - I am converting the PNG map downloaded (when using roadmap) to a truecolor image to prevent problems with conflicting colormaps, so I don't really know why you're having problems.

Maybe you can send me an example code you use, and I will check it out.

10 Aug 2011 Michael Wengler

Outstanding, easy to use, elegant!

08 Oct 2011 Chandrakumar

Hi there zohar,

Hope you are fine,
actually i have a power plot of an antenna radiation level at ground level which spread over some 300 meters. now what i want to do is placing the power plot on a specific region on google earth so that i can see how the power plot is in the region where the antenna is, can you help me?

06 Dec 2011 Oliver

Great work. This works a treat, Thanks!

10 Feb 2012 Erdal Bizkevelci  
02 Mar 2012 Chad Greene

This is unbelievably easy to install and use!

Only one question: it seems to be plotting the 45° angle view, whether I choose roadmap, terrain, or satellite. Any ideas of how to get the overhead image?

06 Mar 2012 Chad Greene

Ah, there's an easy fix: simply add "axis equal" after the plotting command.

23 Mar 2012 Andrea

Hey, great function!

I was wondering one thing. I have to plot a wind map over the ocean, close to the coast. Therefore I would like to get the coastline on the top, and the land just represented as a grey or black surface on top of my contour plot. Is it possible to get the land of the googlemap background on top of my countour plot?

17 Apr 2012 K E

Very nice.

04 May 2012 georg  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
plot Zohar Bar-Yehuda 17 May 2010 12:22:02
google Zohar Bar-Yehuda 17 May 2010 12:22:02
map Zohar Bar-Yehuda 17 May 2010 12:22:02
mapping Zohar Bar-Yehuda 17 May 2010 12:22:02
wgs Zohar Bar-Yehuda 17 May 2010 12:22:02
wgs84 Zohar Bar-Yehuda 17 May 2010 12:22:02
earth sciences Zohar Bar-Yehuda 19 May 2010 17:01:04
potw Lindsay Coutinho 04 May 2012 09:20:16
pick of the week Lindsay Coutinho 04 May 2012 09:20:16
wgs Gerd Kunert 07 May 2012 07:12:43

Contact us at files@mathworks.com