Skip to content

Simple static map retrieval

Rodney Lopes Gomes edited this page Sep 18, 2010 · 1 revision

Retrieve a map of every supported format and maptype and just expect a successful image retrieval and create a few simple functions for image retrieval from the Google Maps Static API V1. So below lets start by writing up a simple function that would allow us to retrieve images from the API we want and hide all of the complicated URL handling and other things behind a function.

<?xml version="1.0" encoding="UTF-8"?>
<function name="get_maps">
    <param name="center"    type="required"/>
    <param name="key"       type="required"/>
    <param name="format"    default="png"/>
    <param name="maptype"   default="roadmap"/>
    <param name="size"      default="128x128"/>
    <param name="zoom"      default="12"/>

    <http_get uri="${static.maps.url}?center=${sf-ll}&amp;zoom=12&amp;size=${size}&amp;key=${static.maps.key}&amp;format=${format}&amp;maptype=${maptype}"/>
</function>

This function can now be used by the tests to download the static maps without having to deal with the details of the underlying API in every test that needs to make this same call. We'll move this function into a function library and call it the static_maps_util.xml that we can now load from any other test.

<?xml version="1.0" encoding="UTF-8"?>
<script xmlns="http://dtf.org/v1" name="simple_map_get">
    <info>
        <author>
            <name>Rodney Gomes</name>
            <email>rlgomes@yahoo-inc.com</email>
        </author>
        <description>
        Simple map retrieval test that does nothing more than retrieve the 
        various formats and maptypes available for a specific map location.
        </description>
    </info>
  
    <local>
        <createstorage id="INPUT" path="${dtf.xml.path}/input"/>
        <createstorage id="OUTPUT" path="${dtf.xml.path}/output"/>
        
        <loadproperties uri="storage://INPUT/maps.properties"/>
        <import uri="storage://INPUT/static_maps_util.xml"/>
      
        <property name="sf-ll" value="37.77445,-122.41885"/>
    </local> 
    
    <for property="maptype" range="${static.maps.maptypes}">
	    <for property="format" range="${static.maps.formats}">
            <call function="get_map">
                <property name="center"     value="${sf-ll}"/>
                <property name="key"        value="${static.maps.key}"/>
                <property name="format"     value="${format}"/>
                <property name="maptype"    value="${maptype}"/>
            </call>
	        <log>downloaded sf_map_${maptype}.${format}</log>
            <log>from ${http.get.uri}</log>
	    </for>
    </for>
    
</script>

The test itself is a no brainer since all we have to do is come up with the list of maptype and format to iterate through and just retrieve everyone of the maps we want to validate are all available.

Clone this wiki locally