UMapper
List of remote methods available within Maps API.

Outline

Simple Maps API, makes it really simple to acceess your user account at UMapper.com directly from your own website. This is done by relying on XML-RPC protocol. If you are new to RPC - start with our tutorial.

In a nutshell, RPC (or Remote Procedure Calls, hence the name RPC) allows you to trigger the procedures located on UMapper.com directly from your PHP application. It is a de facto standard in IT industry, so costs of integration are low.

Theory of operation

General operation sequence when using API would be as following:

  1. Connect to UMapper and obtain session key (see maps.connect()). In order to connect you would need to provide UMapper username, password and API key (obtain it by accessing your UMapper account).
  2. Once connected, use obtained session token along with your API key to invoke any of remote methods described below.
  3. Once executed method returns result, on error exceptions are thrown - so always check your results for exceptions (see test() method) to make sure that your call is successful.

To get you started quickly we have prepared an easy to follow tutorial describing the remote method invocation.

Couple of notes before you start

  1. Arguably the most easy way to utilize the XML-RPC protocol is to use Zend Framework - it has a very rich library of classes. For those who doesn't want to use full Zend Framework, we prepared the Integrator Toolkit. Toolkit contains only those ZF classes that are required to successfully run the XML-RPC client.

  2. All examples are written in PHP5 and use Zend Framework. Thus, in order to be able to run the samples, you either have to install Zend Framework, or use Integrator Toolkit.

  3. IMPORTANT! All XML-RPC requests should be forwarded to

    http://www.umapper.com/services/xmlrpc/

  4. You would need to provide valid credentials in order to use Simple Maps API. Sign up for completely FREE UMapper account, in order to obtain your connection details.

    Test UMapper connection

    In order to check whether your application is able to "talk" to UMapper servers, we have implemented test() method:

    string maps.test([boolean $throwException = false])

    Definition: Test function to check whether server responds or not.

    Name Type Description
    boolean $throwException Flag. Defines whether exception should be produced as result - it is usefull when testing how exceptions are thrown by UMapper servers.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // invoke maps.test() method
        $response = $client->call('maps.test');
       
        // dump the results
        Zend_Debug::dump($response);
    } catch (Exception $e){
        die($e->getMessage());
    }

    Output:

    1
    
    string(20) "RPC Call Sucessfull!"

    If everything goes all right, then you should get the "RPC Call Sucessfull!" message in your browser. If you wanted to test how exceptions are thrown you shuold pass additional parameter to $client->call():

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // invoke maps.test() method; pass $throwException = true
        $response = $client->call('maps.test', array(true));
       
        // dump the results
        Zend_Debug::dump($response);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    UMapper server responds with an exception, which may have the following dump:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    object(Zend_XmlRpc_Client_FaultException)#14 (6) {
      ["message:protected"] => string(15) "Error Occured!!"
      ["string:private"] => string(0) ""
      ["code:protected"] => int(404)
      ["file:protected"] => string(51) "/Zend/XmlRpc/Client.php"
      ["line:protected"] => int(261)
      ["trace:private"] => array(1) {
        [0] => array(6) {
          ["file"] => string(66) "/www/umapper.com/client.php"
          ["line"] => int(12)
          ["function"] => string(4) "call"
          ["class"] => string(18) "Zend_XmlRpc_Client"
          ["type"] => string(2) "->"
          ["args"] => array(2) {
            [0] => string(8) "maps.test"
            [1] => array(1) {
              [0] => bool(true)
            }
          }
        }
      }
    }

    Connect to UMapper

    The very first thing you'd want to do when using the API is to connect to UMapper system. This is accomplished via maps.connect() method. Here is the syntax:

    string maps.connect(string $user, string $pass, string $key)

    Def: You feed this function your credentials and it returns the valid session token you would be using for any successive call to Simple Maps API.

    Name Type Description
    string $user Valid UMapper username. Sign up for an account if you do not have one yet.
    string $pass Valid UMapper account's password (as MD5 hash). Do not provide raw password - hash it with md5().
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    
    /**
     * Zend_Debug
     */

    require_once 'Zend/Debug.php';

    /**
     * Zend_XmlRpc_Client
     */

    require_once 'Zend/XmlRpc/Client.php';

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // setup connection parameters (below are sanbox details)
        $params = array(
            'username'  => 'torio',
            'password'  => md5('password'),
            'key'       => '2f025d840d8ef745b717c4972774a4db',
        );
       
        // invoke RPC method call and get the result into $response variable
        $response = $client->call('maps.connect', $params);
       
        // dump the results
        Zend_Debug::dump($response);
    } catch (Exception $e){
        die($e->getMessage());
    }

    Output:

    1
    
    string(32) "5e63dd036104a157419fe7117c891480"

    As you can see, we do not have to worry about XML being transfered back and forth between your site and UMapper - everything is abstraced in Zend_XmlRpc_Client class. The resultant string (which we saved in $response variable) is your session token, and could be used for successive calls right away.

    Connect to UMapper using API key only

    When you need to connect to UMapper, but do not want to provide your username and password, you can do it by providing just your API key. Here's how:

    string maps.connectByKey(string $key)

    Def: You feed this function your API key and it returns the valid session token you would be using for any successive call to Simple Maps API.

    Name Type Description
    string $key Valid UMapper API Key. Sign up for an account if you do not have one yet.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    /**
     * Zend_Debug
     */

    require_once 'Zend/Debug.php';

    /**
     * Zend_XmlRpc_Client
     */

    require_once 'Zend/XmlRpc/Client.php';

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // setup connection parameters (below are sanbox details)
        $params = array(
            'key'       => '2f025d840d8ef745b717c4972774a4db',
        );
       
        // invoke RPC method call and get the result into $response variable
        $response = $client->call('maps.connectByKey', $params);
       
        // dump the results
        Zend_Debug::dump($response);
    } catch (Exception $e){
        die($e->getMessage());
    }

    Output:

    1
    
    string(32) "a3418121d4daefeece1c63533dd6fad5"

    Verify UMapper API Key

    In order to check whether your API key is valid or not, use maps.verifyApiKey() method:

    boolean maps.verifyApiKey(string $key)

    Def: Checks whether API key is valid or not, boolean true is returned if key is valid, false if otherwiser.

    Name Type Description
    string $key UMapper API Key. Sign up for an account if you do not have one yet.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    /**
     * Zend_Debug
     */

    require_once 'Zend/Debug.php';

    /**
     * Zend_XmlRpc_Client
     */

    require_once 'Zend/XmlRpc/Client.php';

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // setup connection parameters (below are sanbox details)
        $params = array(
            'key'       => '2f025d840d8ef745b717c4972774a4db',
        );
       
        // invoke RPC method call and get the result into $response variable
        $response = $client->call('maps.verifyApiKey', $params);
       
        // dump the results
        Zend_Debug::dump($response);
    } catch (Exception $e){
        die($e->getMessage());
    }

    Output:

    1
    
    bool(true)

    Create new map

    In order to use the UMapper Map Editor, you have to create map record in our database. Use maps.creatMap() method to accomplish this:

    int maps.createMap(string $token, string $key, struct $mapMeta)

    Definition: Creates map (populates map meta-data), Map ID of newly created map record (or zero on error) is returned.

    Name Type Description
    string $token Token identifying the session. This key is produced by initiating maps.connect() method.
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.
    array $mapMeta Associative array containing map data. e.g:
    array(
        'mapTitle'  => 'Some Map',
        'mapDesc'   => 'Here goes some map description'
    )

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // connect (by API key), obtain valid session token
        $params = array('2f025d840d8ef745b717c4972774a4db');
        $token = $client->call('maps.connectByKey', $params);

        // setup map data
        $mapData = array(
            'mapTitle'  => 'My Map',
            'mapDesc'   => 'Sample map created via API'
        );
       
        // setup the payload parameters
        $params = array($token, '2f025d840d8ef745b717c4972774a4db', $mapData);
        // try to create new map for a given session
        $mapId = $client->call('maps.createMap', $params);
       
        Zend_Debug::dump($mapId);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    Output:

    1
    
    int(2164)

    Get map meta-data

    Once map record is created you can retrieve its content by using maps.getMapMeta() method:

    array maps.getMapMeta(string $token, string $key, int $mapId)

    Definition: Retrieves the map meta-data as associative array.

    Name Type Description
    string $token Token identifying the session. This key is produced by initiating api.connect() method.
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.
    int $mapId Map record ID of fetched map.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // connect (by API key), obtain valid session token
        $params = array('2f025d840d8ef745b717c4972774a4db');
        $token = $client->call('maps.connectByKey', $params);

        // get map meta-data for map 2164
        $params = array($token, '2f025d840d8ef745b717c4972774a4db', 2164);
        $mapData = $client->call('maps.getMapMeta', $params);
       
        Zend_Debug::dump($mapData);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    Output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    array(12) {
        ["id"]              => string(4) "2164"
        ["ownerId"]         => string(2) "17"
        ["mapTitle"]        => string(6) "My Map"
        ["mapDesc"]         => string(26) "Sample map created via API"
        ["viewCount"]       => string(1) "0"
        ["commentCount"]    => string(1) "0"
        ["dateCreated"]     => string(19) "2008-08-28 01:57:06"
        ["providerId"]      => string(1) "2"
        ["mapViewPerms"]    => string(6) "anyone"
        ["mapEditPerms"]    => string(2) "me"
        ["sessionId"]       => string(0) ""
        ["traversed"]       => string(1) "1"
    }

    Retrive map URI

    Map source data is stored in XML format (more specifically in highly extensible KML), an in order to load some map into UMapper Map Viewer or UMapper Map Editor, you would need an URI to the KML source file - maps.getMap() was designed for such needs:

    string maps.getMap(string $token, string $key, int $mapId)

    Definition: Returns the path of map file (currently in KML format).

    Name Type Description
    string $token Token identifying the session. This key is produced by initiating api.connect() method.
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.
    int $mapId Map record ID of fetched map.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // connect (by API key), obtain valid session token
        $params = array('2f025d840d8ef745b717c4972774a4db');
        $token = $client->call('maps.connectByKey', $params);

        // get URI of map's KML file, for map ID = 2164
        $params = array($token, '2f025d840d8ef745b717c4972774a4db', 2164);
        $mapUri = $client->call('maps.getMap', $params);
       
        Zend_Debug::dump($mapUri);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    Output:

    1
    
    string(49) "http://umapper.s3.amazonaws.com/maps/kml/2164.kml"

    Generally, it is safe to assume that map URI would be generated as following:

    http://umapper.s3.amazonaws.com/maps/kml/ + mapID

    Still, the function would always return correct source path, so it is advised for forward-compatibility.

    Update map meta-data

    Once your map is created there may be situations when you need to update, say, map title or description - map meta data. This is done with maps.saveMapMeta():

    boolean maps.saveMapMeta(string $token, string $key, int $mapId, struct $mapMeta)

    Definition: Updates map's meta-data. Number of rows updated is returned (generally 1, if operation succeeds).

    Name Type Description
    string $token Token identifying the session. This key is produced by initiating maps.connect() method.
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.
    int $mapId Map record ID of updated map.
    array $mapMeta Associative array containing map data. e.g:
    array(
        'mapTitle'  => 'Some Map',
        'mapDesc'   => 'Here goes some map description'
    )

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // connect (by API key), obtain valid session token
        $params = array('2f025d840d8ef745b717c4972774a4db');
        $token = $client->call('maps.connectByKey', $params);

        // setup updated map data
        $mapData = array(
            'mapTitle'  => 'My Map Updated',
        );
       
        // setup the payload parameters (map ID 2164)
        $params = array($token, '2f025d840d8ef745b717c4972774a4db', 2164, $mapData);
        // update map meta-data
        $response = $client->call('maps.saveMapMeta', $params);
       
        Zend_Debug::dump($response); // should be 1
       
        // get updated map data
        $params = array($token, '2f025d840d8ef745b717c4972774a4db', 2164);
        $mapUpdatedData = $client->call('maps.getMapMeta', $params);
       
        Zend_Debug::dump($mapUpdatedData);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    Output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    bool(true)

    array(12) {
        ["id"]              => string(4) "2164"
        ["ownerId"]         => string(2) "17"
        ["mapTitle"]        => string(14) "My Map Updated"
        ["mapDesc"]         => string(26) "Sample map created via API"
        ["viewCount"]       => string(1) "0"
        ["commentCount"]    => string(1) "0"
        ["dateCreated"]     => string(19) "2008-08-28 01:57:06"
        ["providerId"]      => string(1) "2"
        ["mapViewPerms"]    => string(6) "anyone"
        ["mapEditPerms"]    => string(2) "me"
        ["sessionId"]       => string(0) ""
        ["traversed"]       => string(1) "1"
    }

    Update map data (XML source)

    Map source data is stored in XML format (more specifically in highly extensible KML), and method maps.saveMap is used to associate some KML data with certain map:

    boolean maps.saveMap(string $token, string $key, int $mapId, string $mapData)

    Definition: Updates map's KML data. Boolean true is returned if operation succeeds, false otherwise.

    Name Type Description
    string $token Token identifying the session. This key is produced by initiating maps.connect() method.
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.
    int $mapId Map record ID of updated map.
    string $mapData XML string containing valid KML map.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // connect (by API key), obtain valid session token
        $params = array('2f025d840d8ef745b717c4972774a4db');
        $token = $client->call('maps.connectByKey', $params);

        // get mapData from file (just for readability)
        $mapData = file_get_contents(dirname(__FILE__) . '/myMap.xml');
       
        // update map's KML data
        $params = array($token, '2f025d840d8ef745b717c4972774a4db', 2164, $mapData);
        $response = $client->call('maps.saveMap', $params);
       
        Zend_Debug::dump($response);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    Contents of myMap.xml file:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    <?xml version="1.0" encoding="UTF-8"?>
    <kml
        xmlns="http://earth.google.com/kml/2.1"
        xmlns:umapst="http://www.afcomponents.com/as3/umap/styles"
        xmlns:umap="http://www.afcomponents.com/as3/umap"
    >

    <Document>
        <name>Umapper.com</name>
        <description><![CDATA[My Map]]></description>
        <umap:UMapSettings xmlns:umap="http://www.afcomponents.com/as3/umap">
            <provider>
                com.afcomponents.umap.providers.microsoft::MicrosoftProvider
            </provider>
        </umap:UMapSettings>
    </Document>
    </kml>

    Output:

    1
    
    bool(true)

    Delete Map

    Sometimes maps should be deleted, not surprisingly maps.deleteMap() does exactly that:

    int maps.deleteMap(string $token, string $key, int $mapId)

    Definition: Deletes map and corresponding resources, number of rows (generally 1) is returned.

    Name Type Description
    string $token Token identifying the session. This key is produced by initiating api.connect() method.
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.
    int $mapId Map ID of deleted map.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // connect (by API key), obtain valid session token
        $params = array('2f025d840d8ef745b717c4972774a4db');
        $token = $client->call('maps.connectByKey', $params);
       
        // delete map and associated resources
        $params = array($token, '2f025d840d8ef745b717c4972774a4db', 2164);
        $response = $client->call('maps.deleteMap', $params);
       
        Zend_Debug::dump($response);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    Output:

    1
    
    int(1)

    Return list of user maps

    In order to retrieve the list of maps associated with your account, use maps.getMaps():

    array maps.getMaps(string $token, string $key)

    Definition: Returns array of maps, if any, registered with a given user account.

    Name Type Description
    string $token Token identifying the session. This key is produced by initiating api.connect() method.
    string $key In order to identify that requests are comming from valid client with non-expired credentials we need your API key - just login into your account to obtain it.

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    require_once 'Zend/Debug.php';          // Zend_Debug
    require_once 'Zend/XmlRpc/Client.php';  // Zend_XmlRpc_Client

    // initialize RPC-client
    $client = new Zend_XmlRpc_Client(
        'http://www.umapper.com/services/xmlrpc/'
    );

    try {
        // connect (by API key), obtain valid session token
        $params = array('2f025d840d8ef745b717c4972774a4db');
        $token = $client->call('maps.connectByKey', $params);
       
        // get list of maps
        $params = array($token, '2f025d840d8ef745b717c4972774a4db');
        $maps = $client->call('maps.getMaps', $params);
       
        Zend_Debug::dump($maps);
    } catch (Exception $e){
        Zend_Debug::dump($e);
    }

    Output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    array(2) {
      [0] => array(3) {
        ["id"] => string(4) "2164"
        ["mapTitle"] => string(14) "My Map Updated"
        ["viewCount"] => string(1) "0"
      }
      [1] => array(3) {
        ["id"] => string(4) "2165"
        ["mapTitle"] => string(6) "My Map"
        ["viewCount"] => string(1) "0"
      }
    }