View License

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

» Watch video

Highlights from
get_google_map

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.66667
4.7 | 4 ratings Rate this file 87 Downloads (last 30 days) File Size: 7.62 KB File ID: #24113 Version: 1.4
image thumbnail

get_google_map

by

Val Schmidt (view profile)

 

14 May 2009 (Updated )

Retrieve a google map from the command line using the Static Google Maps API.

| Watch this File

File Information
Description

The function get_google_map.m uses the Google Maps API (https://developers.google.com/maps/documentation/static-maps/) to retrieve a google map image from Google given coordinates of the center of the image and the desired zoom level (default 15). The image is returned as a raster array and a color map.
In addition, an estimate of the X and Y coordinate vectors are returned in UTM coordinates to facilitate easy plotting of additional information on the map from within MATLAB.
The desired height and width of the image (in pixels) may be specified as well as the "MapType" (one of roadmap, mobile, satellite, terrain, hybrid, mapmaker-roadmap, mapmaker-hybrid) and up to 50 Google Map markers. For each marker one may specify the location, size, color and optional label.
Default values: Zoom 15, MapType = 'satellite', Height = 640, Width = 640
One may utilize the Google Maps API without a key for a limited number of queries per day. To utilize the Google Maps API up to 25,000 queries per day, one must obtain a Google Maps API Key, freely available from Google. The key may be obtained here: https://developers.google.com/maps/documentation/static-maps/ (click "Get a Key")

Note, the key requirement places limitations on the portability of this function, as the key, and therefore the function is necessarily tied to a domain name and therefore (usually) a physical location. None-the-less it remains a very handy function for quickly plotting data on a map.

The following code produce the attached screenshot:

[xx yy M Mcolor] = get_google_map(43.06374,-70.703993);
imagesc(XX,YY,M); shading flat; colormap(Mcolor)
xlabel('Eastings UTM')
ylabel('Northings UTM')
title('Entrance to Portsmouth Harbor')

Known Issues:
1) The estimate of the X and Y coordinate vectors are just that, a guess at an algorithm for determining these values from the images size and zoom level. The algorithm was determined by trial and error (as the API provides no way to query for the spacial bounds of an image), and therefore will likely produce poor results for some locations. In the vicinity of Portsmouth Harbor, NH the resulting image is geo-referenced to about +/- 3m.

2) Because of MATLAB's poor rendering performance on the Mac platform, my experience has been that maps plotted as in the example above produce white gaps whose cause and resolution are unknown.

Acknowledgements

Deg2utm and Zoharby/Plot Google Map inspired this file.

This file inspired Zoharby/Plot Google Map.

MATLAB release MATLAB 7.8 (R2009a)
MATLAB Search Path
/
/__MACOSX
/__MACOSX/get_google_map
/get_google_map
Other requirements Requirements: 1) deg2utm.m 2) To query and return a Google Map using the Google Static Map API, Google requires that you have a valid MAPS API KEY.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
01 Jun 2016 Pushkar Limaye  
23 Mar 2016 Martin

Martin (view profile)

Thanks, this is a great function!
I was able to improve the performance by tweaking it to not write the image to a file but using the webread() function to load the image directly - Maybe you want to consider this. - Martin

Comment only
03 Mar 2016 Andoni Medina

Hi!, thanks to my colleague Cezar Stanciu we (mainly him) solved the issue. As handles to figures are now objects, it's required to change the axHandle to double->"double(axHandle)" each time is called in the script. regards

03 Mar 2016 Andoni Medina

Hello, script gives error if used with Matlab 2014b on, due to the graphical handles change. Has any of you experienced this? thanks

22 Sep 2009 brijendra kumar

i am getting following error........
please help me to fix it..................
################
??? Error using ==> imread at 328
Unable to determine the file format.

Error in ==> get_google_map at 163
[M Mcolor] = imread(filename);

Error in ==> Untitled2 at 3
[xx yy M Mcolor] = get_google_map(43.06374,-70.703993);

Comment only
14 May 2009 us

us (view profile)

once the user has set the environment

- get the KEY
- get DEG2UTM

it works quite well for most of the prop/val combinations

two thoughts

no need to FLIPUD(M) in the function... otherwise, users have to flip it back for

imagesc(XX,YY,flipud(M));
colormap(Mcolor);
axis image;

which seems a faster/better way to display the map compared to the proposed SURF(...)

the props should be case-insensitive...

us

Updates
15 May 2009 1.1

I've taken the recommendations made by "us", removing flipud from the code so the resulting image plots with imagesc correctly and making the options case insensitive.

11 May 2010 1.2

No functional change.

03 Mar 2016 1.3

Adopted Google Maps API Key handling from plot_google_map(). Updated to use the new Google Maps API. Uses a new method (requiring the signal processing toolbox) for calibrating the image size.

25 Mar 2016 1.4

Adopted Martin's suggestion (see comments) to use a webread() call rather than a temporary file. Also reorganized the code a bit to make more understandable.

Contact us