Get from Ico-github-logo

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

  • plot_google_map(varargin)
    function h = plot_google_map(varargin)
  • View all files
4.9 | 87 ratings Rate this file 261 Downloads (last 30 days) File Size: 21.5 KB File ID: #27627 Version: 1.9
image thumbnail




16 May 2010 (Updated )

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

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];

Known Issues:
1) The static maps API is limited to 1000 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)
2) Saving the map with an image/matrix overlay drawn on top of it (especially a semi-transparent one) can sometimes cause unexpected results (map not showing etc.). If you're encountering such problems, it's recommended to use the export_fig submission:
The combination that seems to work best:


Get Google Map inspired this file.

This file inspired Visual Inertial Odometry, Jc Dstatus Plot, Landsat, Borders, Gps2 Cart, Get Google Map, and Gitanes.

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (163)
20 Feb 2017 Mos Bay

Great job!
Any idea how to switch to satelite view?

Comment only
07 Dec 2016 Carina Sauter

Amazing, so easy to use :) Thank you!

17 Nov 2016 Ayush Choubey

I wanted to add the scale to the map as we get in google maps(not static).
Is there a way to add a scale?

12 Nov 2016 Joseph Ahamioje

AM sorry. this was the code i eventually used but the png file did not come up. only the google map location came up.

lat = (29.581226);
lon = (-98.617149);
export_fig Capture1.PNG

Comment only
12 Nov 2016 Joseph Ahamioje

i am trying to upload a PV PLANT Circuit and have it draw on google map. i have the coordinates of the place i want to circuit to upload on. i tried this but it only brings out the google map of the location but not the circuit. any tips please?

lat = (29.581226);
lon = (-98.617149);

Comment only
03 Nov 2016 Grant

Grant (view profile)

Thanks Zohar!

29 Oct 2016 Cory Johnson

11 Oct 2016 Lukas Pfeiffer

I really like the function...and used it for creating maps which I now want to use in a student thesis.
Is there anyone who has an idea how to correctly cite the plots?
In wanted to mention it in the text by typing '.....(Google Maps, 2016).'
But what do I have to write in my 'Reference' list?
Something like:

Google Maps (2016). New York - Paris - London. (Created using plot_google_map, Zohar Bar-Yehuda).

- do I have to find out/ mention any URL which might be used in the background?
- do I have to mention Static Google Map API?
- is there any 'location'/ (where and how) do I have to mention that the function is from MATLAB fileExchange?

I hope that someone comes up with a good solution...
Thanks in advance,

Comment only
07 Oct 2016 Shital shirsat rohekar

I also see taht plot_google_map.m alters my colorbar range .. Pleasecould you suggest why ?

Comment only
07 Oct 2016 Shital shirsat rohekar

Hi..thats Wonderful. But please could you help me with a small problem.. I need to plot air pollution data (as coloured circles) on top of the map.the colour of the circles should vary based on the concentration and also have a colorbar. Is there some easy way to do this..Many thanks.SSR

03 Oct 2016 David

David (view profile)

great tool! thanks!

27 Jul 2016 adnan ali awan

I keep on getting this error!!!!
>> plot_google_map
Out of memory. The likely cause is an infinite recursion within the program.

Error in newplot>ObserveAxesNextPlot (line 124)
cla(ax, 'reset',hsave);

Comment only
03 Jun 2016 Shibing Liu



Great work.

26 May 2016 Andrés

muy bueno

06 May 2016 Cory Johnson

04 May 2016 Evan Kalina

23 Apr 2016 Fahad Furniturewala

I am getting this error and it sets all my points on a fixed axis (like a straight line) and the map doesnt show up.
Error using ==> set
Bad property value found.
Object Name : axes
Property Name : 'YLim'
Values must be increasing and non-NaN.

Can somebody help please?

31 Mar 2016 MUTHUKUMAR S

Good work sir
If user wants to move from one country to other by dragging, it takes time to load.
How to decrease the time delay in loading?
What changes can be done such that the location of countries can be viewed in world map at once?

I am Waiting Sir

23 Mar 2016 Kanishke Gamagedara

05 Mar 2016 Brian Sutton

09 Feb 2016 Peter Mills

Great mapping tool. I would really like to plot a wind rose on the Google map at the location of the recording station. How can I do this?

01 Feb 2016 Shelley Hung

04 Dec 2015 Carlos

Carlos (view profile)

Great tool. I'm using this to plot a trajectory... I am having an issues with grabbing points using the selectdata function on file exchange. Specifically, it will detect several points besides the trajectory plotted onto the google map. Any suggestions on how to get rid of these hidden data points? Thanks

01 Dec 2015 Zohar Bar-Yehuda

@lostreet - can you send me a code sample that illustrates your colors problem?
As far as I know this shouldn't happen.

Comment only
24 Nov 2015 lostreet

I am trying to plot a semitransparent contourf on top of the google map. Unfortunately the colors of the contourf plot are changing when added to the google map. Do you have a solution for this problem?

Comment only
15 Nov 2015 Tuan Nguyen

12 Nov 2015 Seyedfarid Ghahari

How can I see the map in tilted view?

Comment only
12 Nov 2015 Zohar Bar-Yehuda

@DHRUPAL SHAH - issued a fix for this (in case there are no permissions to temp folder, use the current folder instead). Should solve your problem

Comment only
09 Nov 2015 DHRUPAL SHAH

Great Use.
Faced a very unethical error for 4 hours of windows user not having access to "Temp" folder.
Solution: Randomly figured our to use matlab as "Run as Admin".

20 Oct 2015 Zohar Bar-Yehuda

@lostreet - pushed a fix for this warning. Download the current version.

Comment only
20 Oct 2015 lostreet

I have one more question.

When executing the code I always get this warning:

Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2 Release Notes,
Assigning Nonstructure Variables As Structures Displays Warning, for details.
> In plot_google_map at 180

How do I have to change the code to avoid it?

Comment only
13 Oct 2015 lostreet

I found the solution to my problem in the previous answers.

"The easiest way would be to set the zoom level you want manually (using xlim/ylim or the axis command), and then call plot_google_map again to force it to refresh to the current zoom."

Comment only
13 Oct 2015 lostreet

Really good tool.

I have the same question as Rezka: Is it possible to zoom automatically in a required area? Thank you for your help

Comment only
13 Oct 2015 lostreet

05 Oct 2015 Jasmin McInerney

Hi, having trouble working with contour and contourf, the colours of my contour are being overwritten with blue. In the code below I have tried to move "plot_google_map(...)" down to the end with the same results. Note red x from plot command are staying red. Has anyone worked out how to fix this?

plot(Xs, Ys, 'xr')
plot_google_map('MapType', 'satellite','Alpha', 1)
hold on
contourf(xq, yq, Things)

22 Sep 2015 Kelly Kyriakou

Precious tool!!!!

18 Sep 2015 Rezka

Rezka (view profile)

Really helps. Thanks Zohar.
I want to know which code that i have to modified to zooming the map automatically without tools from the figure options.
Thanks, best regards

26 Aug 2015 Bruno Dias

I think this project is quite interesting.
I've worked on something similar in Google Earth so I would like to clarify some doubts.

Could you tell me what do you do when you "project the data into a uniform WGS1984 grid" and use myTurboInterp2() function?

The resolution varies with the latitude. Could you explain how you make image adjustment to correct this problem?

You use the resolution measured at Equator. Many documentation refers to multiply cos(lat * pi/180) when you determine curResolution.

Thanks, Bruno Dias

05 Jul 2015 Zohar Bar-Yehuda

Pete - update to the latest version of the code. It solves this issue.

Comment only
30 Jun 2015 Pete sherer

I think it has an issue with v2015a
inputParams.(['ax' num2str(axHandle*1e6,'%.0f')]). It returns error.

28 Jun 2015 Zohar Bar-Yehuda

Marc - thanks for the tip. I'll add it in the next update.

Comment only
24 Jun 2015 Tim Kaufmann

23 Jun 2015 Marc

Marc (view profile)

Hi Zohar,

I have made a very small change that improved speed quiet a bit. I replace data=urlwrite(filename,url) by M=webread(url), using webread that was introduced in R2014b. This avoid the TMP image to be saved in the current folder and therefore to write to the disk. It might be a good idea to update the actual version with it.


20 Jun 2015 snrlax

snrlax (view profile)

Hi Zohar,

The toolbox is awesome and it has helped me a lot. I now would like to use it for another purpose, 3D plotting. Is it possible to plot the map in the xOy plane for example?

The goal is to do a 3D bar plot, with the bars over specific locations.


24 May 2015 Zohar Bar-Yehuda

Carine - use:
point = ginput(1);
a click on the map will then return the longitude and latitude of the point.

Comment only
20 May 2015 Carine

Carine (view profile)

Hi Zohar,

Thank you for this great toolbox.
I am very new in mapping so I hope my question does make sense: I would need, from the google map, a user to click on a place and receive the coordinates of this place. Is this possible?

08 May 2015 Hector Usach

Regarding my last comment, I'm sorry, I didn't realised that the problem I mention (text not clear in the figure) just happens when using a tex interpreter, so it seems more a matlab bug than a problem of this function.

Comment only
08 May 2015 Hector Usach

06 May 2015 Zohar Bar-Yehuda

Ron - scale is still there, default is scale=2.

Hector - Not sure I understand your problem. Send me more details and an example to and I'll try to help.

Comment only
05 May 2015 Hector Usach

Works great, but when there is text on the figure, it appears blurred. Actually the ylabel is cut. Any solutions? (Matlab 2012b)

05 May 2015 Ron Abileah

Would give it 10 stars if I could. Thank you very much for sharing. An earlier version had the Scale=2 option. This seems to have gone away in the 2014 update. Is there a reason?

25 Mar 2015 Ilyas

Ilyas (view profile)

Hey thanks for this. Very useful. However when the plot is rotated with the rotate 3D tool, the map disappears. Is there a way to keep it in its position?

22 Mar 2015 pietro

pietro (view profile)

Is it possible to have a higher image quality of the map?

Comment only
02 Mar 2015 Giorgos Papakonstantinou

02 Mar 2015 Zohar Bar-Yehuda

Wyfi Mcfly - fixed in latest version (used a more elegant solution using 'UserData' field in handle. Please update to latest version.

Comment only
25 Feb 2015 Wyfi Mcfly

R2014 broken on line 109
fix by casting ax handle to double

inputParams.(['ax' num2str(double(axHandle)*1e6,'%.0f')]) = varargin;

Comment only
12 Feb 2015 schwarzkater

I love you!! (just kidding)

Your script is very, very useful.

24 Jan 2015 NickG

NickG (view profile)

Hi this is a great tool and works well for me when I run it normally. I am having issues when trying to run the code through MATLAB publisher. MATLAB hangs and does not publish the plot. Has anyone else encountered this?

Comment only
12 Jan 2015 Jian

Jian (view profile)

Fantastic tool!

Does it work for 3D plots? I tried to use it on a plot generated by plot3 function, but it did not work. Any suggestions?



12 Jan 2015 Jian

Jian (view profile)

18 Dec 2014 markus

markus (view profile)

Great tool!
Starting with Matlab 2014b I got big problems with scattered plots and color-bars. The color-bar stopped fitting to the scattered plot after plot_google_map was executed.
I had to change line 415 to solve the problem:
h = image(lonVect,latVect,uniImag, 'Parent', axHandle,'cdatamapping','scaled');


04 Dec 2014 Jeff Jackson

Jeff Jackson (view profile)

27 Nov 2014 Ilya Shipachev

Great reinforsment to work with GPS data.

20 Nov 2014 Gijs

Gijs (view profile)

Update from previous rating -- the code was modified to work with 2014b, so I'm changing my previous 4* rating to 5*!

17 Nov 2014 Alireza

Hello Zohar,
I was wondering if it's possible to download Google Maps and have it on computer and plot the coordinates without having internet?
also is it possible to have the initial plot with a desired zoom level.


Comment only
11 Nov 2014 Giorgos Papakonstantinou

Hi Zonar and thank you for you nice submission.
As already users have previously noted, there is an issue when running the code with R2014b, which originates from the fact the every handle is an object and not a double.

You have nicely included a ResizeFcn, which is invoked when the figure is resized.
In the ResizeFcn you use break in the for loop. Can you explain me the reason of doing that?
Because if you have two axes with google maps
subplot(1,2,1); plot_google_map; subplot(1,2,2); plot_google_map;

the ResizeFcn function does not re-plot both maps and you turn up with a bad resolution in one of the two.

06 Nov 2014 Gijs

Gijs (view profile)

This is a helpful piece of code.

Unfortunately, as mentioned below, it breaks with 2014b. I'm having an issue at line 109 (inputParams.(['ax' num2str(axHandle*1e6,'%.0f')]) = varargin;). The error message that I'm getting is: "Undefined function 'mtimes' for input arguments of type ''."

01 Nov 2014 Shameek

30 Oct 2014 Sunil Dowray

Thanks a lot for your response Zohar.. As you said, for loop is creating the issue in zooming speed.

26 Oct 2014 Zohar Bar-Yehuda

Larry - thanks for the heads up. I'm very busy in the coming weeks, will fix and release a new version as soon as I have some free time.

Comment only
22 Oct 2014 Sunil Dowray

22 Oct 2014 Sunil Dowray

Hi Zohar, thanks for sharing this wonderful piece of code. I have a query, I'm trying to plot data points which are mapped on to corresponding co-ordinates. The problem is, the number of data points are large (around 15000 - 35000 points). I'm able to plot these data points on the map, but facing issues in zooming/panning speed. The map reaction becomes too slow whenever I try to zoom in or out with the data points on the map. Is there any limitations in the number of points on the map or should I check for any other parameter to overcome this issue.. Thanks

Comment only
21 Oct 2014 Larry

Larry (view profile)

plot_google_map() has broken with R2014b. (No sure about R2014a)

Line 108 gca returns now returns an axes object instead of a double as previously.

Comment only
06 Oct 2014 pietro

pietro (view profile)

06 Oct 2014 Zohar Bar-Yehuda

Pietro - such a feature can be added quite easily.

In the meantime, if you have the mapping toolbox, you can use a few lines of code to achieve this:

load toolbox\map\mapdisp\private\regions.mat worldRegions
axis([worldRegions(pos).lonlim worldRegions(pos).latlim])

Comment only
03 Oct 2014 pietro

pietro (view profile)

Is it possible to provide a string to the function like "Turkey" and getting a map of Turkey?

24 Sep 2014 Nebitno

31 Aug 2014 Zohar Bar-Yehuda

wiwi - there seem to be random errors with some computer IPs.
Try obtaining an API key from Google and setting it, it would probably solve your problem.

If you need more help, feel free to contact me:

Comment only
28 Aug 2014 wiwi

wiwi (view profile)

Hi Zohar, this code does not work for me. It displays only the lat and long nodes. I have an error "Warning: Unable to download map form Google Servers.\nPossible reasons: no network connection, or quota exceeded (1000
map requests per day).
> In plot_google_map at 186"

I'm using Matlab2014a. Please help me!!! thanks

Comment only
14 Aug 2014 Gary

Gary (view profile)

Interesting - worked just fine on a different computer. Sorry of for the false alarm.

Comment only
13 Aug 2014 Zohar Bar-Yehuda

Gary - works fine here without a key. Maybe it depends on your IP which is treated differently by Google for some reason.
Anyway, obtaining an API key and setting it is a matter of minutes, and would probably solve your problem.

Comment only
13 Aug 2014 Gary

Gary (view profile)

Did Google just change something that broke this? The code-generated URL states that a API key is required, but the link you provided in get_google_map for obtaining a key says that keys aren't needed anymore.

Comment only
13 Aug 2014 Mevlut

Mevlut (view profile)

Great work Zohar. I've one question:
If you use this code:

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];

How do the plot_google_map know to use the variables lat and lon?
I've tried with 4 variables:

latR= [1 2 3 4]
lonR = [1 2 3 4]
latG =[1 2 3 4]
long = [1 2 3 4]
hold on, plot(lonR,latR,'.r','MarkerSize',20)
hold on, plot(lonG,latG,'.g','MarkerSize',10)

It works perfectly!! BUT, how do the function plot_google_map know it to take that 4 variables?

Great work, thank you

12 Aug 2014 SURAJ

SURAJ (view profile)

Hey Nice Work.

If you can add a script save map tiles on the computer it will reduce the requirement of API key. API key will be used only to to download additional maps or when required to update.

16 Jul 2014 Oriol Casamor Martinell

GREAT script. What is the relation between the image I see in the figure and the image output of the script? I need to relate latVec and lonVec with the image I obtain from saveas.


15 Jul 2014 Nebitno

13 Jul 2014 pietro

pietro (view profile)

Is it possible to get from google maps the position of commercial spots(e.g. restaurants, hotels, etc) in the map?

Comment only
02 Jul 2014 Zohar Bar-Yehuda

Shatrughan - awesome tip. I will try to integrate it into the script soon.

Comment only
01 Jul 2014 Shatrughan

hello Zohar,

Hope you remember as I pointed out the need to put 'map scale' on the google plots. You said that you will work on it later when you get time. It seems this is still a persistent issue with all users using your anyway 'GREAT' script. However, I have come across another submission on FEX for making scale and very simply I have been using these two scripts for my purpose since long time. Just thought that this might help others and also to you as it might save a bit of your time. :)

Here the link is:

After using plot_google_map
just use makescale

and you are done !!

Happy Matlabbing !!!

Comment only
01 Jul 2014 pietro

pietro (view profile)

Hi Zohar, thanks for your reply. I found this function that it is quite useful, unfortunately I can't control the scale, like 1:20000, but I can get only the distance.

Comment only
29 Jun 2014 Zohar Bar-Yehuda

pietro - that would be quite tricky, as it also depends on your screen size etc.
I wanted to add a scale indicator at the bottom of the map, but never got to it. Hope to add it sometime...

Comment only
25 Jun 2014 pietro

pietro (view profile)

Great job. Is it possible to control the map scale? By istance generating plots with a map scale of 1:20,000. Thanks

Comment only
16 Jun 2014 Jorge

Jorge (view profile)

Zohar, I assumed that you knew about OSM tiles since you've displayed an impressibly awesome work with this function! My comment was more of an open thought directed at other members =)

Comment only
10 Jun 2014 Zohar Bar-Yehuda

Jorge - working with tiles has its upsides (you can choose the resolution you want, possibility for local caching etc.), but will make the code much more complicated and slower to run since it will require several images to be downloaded for every map you want to display.
I don't have plans to get to it in the near future...
I don't plan

Comment only
09 Jun 2014 Jorge

Jorge (view profile)

Amazing! My only comment is, would it make sense to pull the tiles from OpenStreetMap? For example, OSM tiles stored by MapQuest could be accessed even at 4000 tiles/second!

And are pulled simply like where x and y are easily calculated from the desired coordinates:

This way Google limits could be avoided, given OSM is now a very mature project. I would gladly implement this if I had the time, but I thought that maybe anyone else here is annoyed by Google and could use the idea =)

23 May 2014 Zohar Bar-Yehuda

Hi David,

The easiest way would be to set the zoom level you want manually (using xlim/ylim or the axis command), and then call plot_google_map again to force it to refresh to the current zoom.

Comment only
23 May 2014 David

David (view profile)

Great code! I can't figure out how to zoom in to a specific location. Using the comand zoom(15) will not zoom on my GPS point.

Is there any way to set the ylim and xlim of the graph (using those commands the map does not refresh)? I'm trying to use it in a loop to visualize my bicycle ride (needs to be pretty zoomed in)

Comment only
15 May 2014 David Radin

Update to my comment below:

Realized the error was due to a bad coordinate reference - if coordinates do not fit on global plane, well, errors happen.

Comment only
15 May 2014 David Radin

Zohar -
First of all, great function, great utility.

Wondering if you could comment on an error that suddenly appeared. The script was running perfectly but today I started it up and now it is not. I receive the following error:

Error using set
Bad property value found.
Object Name : axes
Property Name : 'YLim'
Values must be increasing and non-NaN.

Error in axis>LocSetLimits (line 206)

Error in axis (line 94)

Error in plot_google_map (line 250)
axis(curAxis) % update axis as quickly as possible, before downloading new image

Error in test (line 11)
plot_google_map('APIKey','**key hidden**')

Appreciate your time!

13 May 2014 Xavier

Xavier (view profile)

Thanks for your quick feedback. In the meantime, I found a solution, I had "'PaperPositionMode','auto'" to the figure properties in addition of "'visible','off'" and it works pretty well and this allow to gain a lot f computing time.

Comment only
13 May 2014 Zohar Bar-Yehuda

OK, turns out the previous comment didn't get through...
Anyway, Xavier - the problem is caused because plot_google_map set a custom figure resize callback to change the zoom if the figure is resized and changes its aspect ratio.
You can disable it by commenting out line 434 which sets the figure resize callback:
set(figHandle, 'ResizeFcn', @update_google_map_fig);

Comment only
13 May 2014 Zohar Bar-Yehuda

Hey, sorry my mistake, that flag was only in some local version I had here.
To resolve your problem comment out line 434:
set(figHandle, 'ResizeFcn', @update_google_map_fig);

Comment only
12 May 2014 Xavier

Xavier (view profile)

First thanks a lot for this script which is very useful.
I got a question where I did not find a solution myself. I use this script into a loop where each iteration represents a trip. I save the figure into png file. I would like to the figure does not appear. I used figure('Visible','off') but figures appear at the saveas command (found out though debug mode) but not if plot_google_map command is removed. I looked at line 379 and so on but without finding a solution. Do you have an idea?

09 May 2014 mizuki

04 May 2014 Zohar Bar-Yehuda

Hi Jason,

From you error, it seems you are using a very old version of MATLAB, in which the syntax of the zoom command is different.
You can make it work by disabling all the functionality involving the auto refresh feature. Comment out lines 421-429.
This should make it work for you, but you'll need to call plot_google_map again if you want the map to refresh after you zoom in or out.

Comment only
02 May 2014 Jason Oh

This is my error message below ;

??? Output argument "out" (and maybe others) not assigned during call to "C:\Program Files (x86)\MATLAB71\toolbox\matlab\graph2d\zoom.m (zoom)".

Error in ==> zoom at 81
if nargin==2 && ...

Error in ==> plot_google_map at 421
zoomHandle = zoom;

Do you know why I got this message?

30 Apr 2014 Mani

Mani (view profile)

Thank you for developing this Zohar. I can use it for a project I am working on. Is it possible to add area measurements tool to this map? If yes, how?
Thank You!!

Comment only
14 Apr 2014 Clemens

Just figured out: After rendering with set(gcf,'renderer','opengl'), even saveas(gcf, 'out.jpg') works.

Comment only
14 Apr 2014 Clemens

Hi Zohar,

thank you a lot for your support! I tried your suggestion and with the rendering setting of set(gcf,'renderer','zbuffer'), the background (map) + transparent settings vanished again.

set(gcf,'renderer','opengl') and exporting with export_fig.m though works for me :)

Best Regards

Comment only
09 Apr 2014 Zohar Bar-Yehuda

Hi Clemens,

I've updated the Known Issues section, hopefully addressing your problem. Hope this helps:

2) Saving the map with an image/matrix overlay drawn on top of it (especially a semi-transparent one) can sometimes cause unexpected results (map not showing etc.). If you're encountering such problems, it's recommended to use the export_fig submission:
The combination that seems to work best:

Comment only
09 Apr 2014 Clemens

Works perfectly for me. I have only the issue already raised by Larry, that if I export my figure to a picture, the map is missing. Do others also have troubles with that or any workaround except screenshots?

26 Mar 2014 Roger GALLOU

Hi Zohar,

I've the same message as Larry. When I post URL given in example in a Web browser (Firefox with no proxy configured), I can see the staticmap of Google Maps.
I've not problems with my quotas and I've really loaded the last version.
Can you give me some help on what it happens ?

Thanks. Regards.

Comment only
19 Feb 2014 Anuja

Anuja (view profile)

Kudos to you, Its really nice, working fine for me...I tried it with two points.
I really wanted to ask one thing, How can we extract the latitude longitude points between two points as in between the source and the destination, Do we have to enter it manually or do we require some coding for the same.

Comment only
08 Feb 2014 Zohar Bar-Yehuda

Larry, are you sure you're using the latest version?
If yes, you can try putting a breakpoint at line 316 - urlwrite(url,filename);
copy the url to your browser and see if it works there.
Anyway, if you need more help feel free to contact me:

Comment only
07 Feb 2014 Larry

Larry (view profile)

For couple of days plot_google_map can't be used, in both my computer and my colleague's. It kept showing:

Warning: Unable to download map form Google Servers.
Possible reasons: no network connection, or quota exceeded.
Consider using an API key if quota problems persist.
> In plot_google_map at 318

My quota is not a problem. I also have tried to use the API key but to no avail. Any idea?


06 Feb 2014 Rajiv

Rajiv (view profile)

Great script. It shows little error for me showing:zoom error. It shows red marker first, then only the map not the red makers.One or more output arguments not assigned during call to 'D:\MATLAB7\toolbox\matlab\graph2d\zoom.m (zoom)'.
Error in ==> plot_google_map at 402
zoomHandle = zoom;
Error in ==> test at 16
Please help how to make it run?

18 Dec 2013 Zohar Bar-Yehuda

Naveed - v3 is only for the javascript API. This code uses the Static Maps API which still uses v2.

If you already have the heatmap data as a matrix, you can simply plot it with IMAGE and give an AlphaData matrix with values <1 to make it semi transperent.
If you have point data, you'll first need to convert it to a heatmap matrix. I need to do it myself for a project in the coming weeks. If I don't find an existing solution I'll probably create one and hopefully submit it to the FEX.

Comment only
17 Dec 2013 Naveed

Naveed (view profile)

Hey, thanks for this great code! Just what I needed. Quick question: are you planning on upgrading this to the v3 of google maps API? Also, could you recommend how to add a heat map layer to the rendered map?

15 Dec 2013 Zohar Bar-Yehuda

Gabriel - there shouldn't be any recursion in this code. Please send me an example how to reproduce the error.

Comment only
10 Dec 2013 Gabriel

I was able to do a plot once or twice, but now I am reaching max. recursion limit all the time. Any help?

Comment only
24 Nov 2013 Zohar Bar-Yehuda

Konstantinos - Simply call plot_google_map after plotting the route. It should display the map in the background of the route.

Comment only
24 Nov 2013 Konstantinos

Great job, and really helpful. I' m trying to plot a certain route on the map which is in a gpx file, which i created from google maps. I use the gpxread function to read the file , I can display the route on a seperate window, but i don't know how to display the route on the map. Does anyone have any idea?

Comment only
14 Oct 2013 Alexandre

Hello Zohar!
With your new code and after cheking mine It seems that the map isn't stretched (also when you remove "axis equal" ....). Many Thanks

14 Oct 2013 Zohar Bar-Yehuda

Alexandre - I think what you mean is that the map is stretched in one axis, which shouldn't happen with the new version.
If you're having the same problem with the new version, please send me an example code to reproduce the problem.

Comment only
11 Oct 2013 Alexandre

Nice job, very useful, many thanks. But I exactly have the same question as Chad Greene (Mar 2012). Does anyone know how to get the image in overhead view instead of 60° inclinaison? Thanks

Comment only
23 Aug 2013 Preetham Manjunatha

Really good one! I was planning to make a GPS tracker for my project, I found exactly what I am looking for. But needs quite a bit of work to make this for realtime tracking or for post-processing.

11 Jun 2013 eder vidaurre gonzales

me sale este error a que se debe : Output argument "varargout" (and maybe others) not assigned during call to "E:\plot_google_map.m>plot_google_map".

Comment only
20 Apr 2013 Giacomo Alessandroni

26 Mar 2013 Larry

Larry (view profile)

Thanks, Seb. It is a wonderful tool.

25 Mar 2013 Seb Biass

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

Comment only
25 Mar 2013 Larry

Larry (view profile)

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);

Comment only
15 Mar 2013 Larry

Larry (view profile)

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...)

Comment only
15 Nov 2012 peter

peter (view profile)

09 Nov 2012 Floris

Floris (view profile)

Hi Amit,

the 640*640 limit is set by the google API. see for more information

Comment only
09 Nov 2012 Amit

Amit (view profile)

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

Thanks again.

Comment only
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.

Comment only
13 Jul 2012 Heiko

Heiko (view profile)

12 Jul 2012 Kart

Kart (view profile)

I tried it with my own API key

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.

Comment only
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) 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.

Comment only
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:

Comment only
13 Jun 2012 Marco

Marco (view profile)

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!


08 Jun 2012 Mint Sauce

04 May 2012 georg

georg (view profile)

17 Apr 2012 K E

K E (view profile)

Very nice.

23 Mar 2012 Andrea

Andrea (view profile)

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

Chad Greene (view profile)

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

02 Mar 2012 Chad Greene

Chad Greene (view profile)

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?

Comment only
10 Feb 2012 Erdal Bizkevelci

06 Dec 2011 Oliver

Oliver (view profile)

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?

Comment only
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.

Comment only
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?


Comment only
15 Nov 2010 Aaron Holtzman

09 Oct 2010 danish zubairi

made my life easier

23 Sep 2010 Gary

Gary (view profile)

24 Jun 2010 Jan Vidar

18 Jun 2012 1.2

- 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.

07 Oct 2013 1.4

- Improved functionality of AutoAxis, which now handles any shape of map axes.
Now also updates the extent of the map if the figure is resized.
- Added the ShowLabels param which allows hiding the textual labels on the map.

25 Mar 2014 1.5

Version 1.4 - 25/03/2014
      - Added the language parameter for showing labels in a local language
      - Display the URL on error to allow easier debugging of API errors

10 Apr 2014 1.6

known issues (map saving alternative with export_fig)

20 Nov 2014 1.7

Version 1.5 - 20/11/2014
       - Support for MATLAB R2014b
       - several fixes complex layouts: several maps in one figure,
         map inside a panel, specifying axis handle as input (thanks to Luke Plausin)

21 Oct 2015 1.8

Revert description

13 Jul 2016 1.9

Version 1.6 - 12/11/2015
       - Use system temp folder for writing image files (with fallback to current dir if missing write permissions)

Contact us