The function get_google_map.m uses the Google Maps API (http://code.google.com/apis/maps/documentation/staticmaps) 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
To utilize the Google Maps API, one must obtain a Google Maps API Key, freely available from Google. The key may be obtained here: http://code.google.com/apis/maps/signup.html. Once obtained the key is simply pasted into get_google_map.m on the line defining the MAPS_API_KEY variable.
Note, this 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,'edgecolor','none'); view(0,90)
colormap(Mcolor)
axis image
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.
|