Code covered by the BSD License  

Highlights from
plot_google_map

5.0

5.0 | 22 ratings Rate this file 168 Downloads (last 30 days) File Size: 6.11 KB File ID: #27627
image thumbnail

plot_google_map

by Zohar Bar-Yehuda

 

16 May 2010 (Updated 18 Jun 2012)

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 static maps API is limited to 400 requests per day when used with no API key. If you use this function a lot, you can obtain an API key and easily set the function to use it (see help for more details)

Acknowledgements

Get Google Map inspired this file.

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File  
Everyone's Tags
earth sciences, google(2), google earth, kml, map(2), mapping, pick of the week, plot, potw, wgs(2), wgs84
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (35)
20 Apr 2013 Giacomo Alessandroni  
26 Mar 2013 Larry

Thanks, Seb. It is a wonderful tool.

25 Mar 2013 Seb Biass

My mistake, had an old version, updated one works like a charm!

25 Mar 2013 Larry

It seems to be incompatible with pcolor. Matlab can plot with both pcolor and plot_google_map, but when the plot is saved as an image (as any format such as png), the background google map is gone.

25 Mar 2013 Seb Biass

Hi there,
Does anyone has any problem with that script recently? It was running smoothly until today.
??? Error using ==> imread at 387
Unable to determine the file format.

Error in ==> plot_google_map at 189
[M Mcolor] = imread(filename);

15 Mar 2013 Larry  
22 Nov 2012 Zohar Bar-Yehuda

Amit, with the new scale=2 param which is used by default, you actually get a 1280x1280 image, which gives a much nicer rendering (though responds somewhat slower...)

15 Nov 2012 peter  
09 Nov 2012 Floris

Hi Amit,

the 640*640 limit is set by the google API. see https://developers.google.com/maps/documentation/staticmaps/index for more information

09 Nov 2012 Amit

Good work there Zohar Bar-Yehuda. And very helpful for my work, thank you.
Though I wonder why is the image size limited to 640X640. It would be very helpful to have this limitation removed. Perhaps a good idea to have the image sized in proportion to screen size. Screen size can be obtained from
java.awt.Toolkit.getDefaultToolkit().getScreenSize()

Thanks again.

08 Aug 2012 Sebastian Holmqvist

From what I've gathered, Google switched from counting usage per domain to per user instead. So basically if you use Static Maps on your website, a single user using up all of the quota won't affect any other users, only that particular user.

Other than that, great piece of software! It was easy to get compatible with older Matlab (2003) and works like a charm under Matlab R2008b.

As for future requests, caching (i.e renaming and not removing) tiles would be awesome! I realize that storing tiles might violate Google's terms, but temporary would certainly do the trick!

15 Jul 2012 Zohar Bar-Yehuda

Kart - I think there is a problem with the API key mode. It seems like Google ignores it since the requests have no referrer field in the HTTP header. Will try investigating it for a solution.

13 Jul 2012 Heiko  
12 Jul 2012 Kart

I tried it with my own API key
plot_google_map(‘APIKey’,'xxxxxxxxxxxxxxxxxxxxxxxxxx’)

but Iam getting the warning quota exceeded. what should i do?

26 Jun 2012 Zohar Bar-Yehuda

Scale is a great idea, and quite easy to implement. I'll try adding it when I have some time.

26 Jun 2012 Shatrughan

Great script !! simple and easy to use..however, I have a question, how to put map scale on the plot? also if you could add direction symbol (North/South)..it would be great..any response will be appreciated..

14 Jun 2012 Zohar Bar-Yehuda

Just noticed they changed the API and introduced the API key again.
It doesn't say what's the limit if you don't use any key, but from a quick test it looks like it's 400 per day (per IP I guess).

If you do get your own key, you can use up to 25,000 requests per day. I'll try to upload a new version soon with an easy way to put your own key.

14 Jun 2012 Zohar Bar-Yehuda

Hi Marco,

This function uses Google's Static Maps API, and is therefore perfectly legal. It's also limited to 1000 map requests per day as specified in the API. See:
https://developers.google.com/maps/documentation/staticmaps/

13 Jun 2012 Marco

Have anyone considered possible legal issues in this application?
As far as i know, it's forbidden the access to the maps through the direct creation of the url.
The access is legal only through the api's google offers (such as javascript).

In case you have different informations please let us know!

Thanks

08 Jun 2012 Mint Sauce  
04 May 2012 georg  
17 Apr 2012 K E

Very nice.

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?

06 Mar 2012 Chad Greene

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

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?

10 Feb 2012 Erdal Bizkevelci  
06 Dec 2011 Oliver

Great work. This works a treat, Thanks!

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?

10 Aug 2011 Michael Wengler

Outstanding, easy to use, elegant!

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.

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!

15 Nov 2010 Aaron Holtzman  
09 Oct 2010 danish zubairi

made my life easier

23 Sep 2010 Gary  
24 Jun 2010 Jan Vidar  
Updates
18 Jun 2012

- Support use of the "scale=2" parameter by default for finer rendering (set scale=1 if too slow).
- Auto-adjust axis extent so the map isn't stretched.
- Set and use an API key which enables a much higher usage volume per day.

Contact us