Display and clear a route on a map by using a location document

You can use a location document to display a route on a map in BlackBerry® Maps. You can also clear a route from a map after it is displayed.
  1. Import the required classes.
    import net.rim.blackberry.api.invoke.*;
  2. Create a class and constructor to use to invoke BlackBerry Maps.
    public class invokeMaps
    {
       public invokeMaps ()
       {
       }
    }
  3. In the constructor, create a String variable to use for the location document. Add an <lbs> and a <getRoute> element. Add <location> elements to specify the starting location and ending location of the route that you want to display.
    String document = "<lbs id='WatRoute'><getRoute>
        <location x='-8052237' y='4346518'
           label='Waterloo, ON' description='Waterloo, Ontario, Canada' />
        <location x='-7569792' y='4542349'
           label='Ottawa, ON' description='Ottawa, Ontario, Canada' />
        </getRoute></lbs>";
  4. In the constructor, invoke Invoke.invokeApplication() using the APP_TYPE_MAPS constant and a new MapsArguments object as parameters to open BlackBerry Maps. Pass in the ARG_LOCATION_DOCUMENT property and the String variable that represents the location document as parameters for the MapsArguments class to display the route provided in the location document.
    invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments
        (MapsArguments.ARG_LOCATION_DOCUMENT, document));
  5. Perform one of the following tasks to clear route location information from a map after it has been displayed:

    Task

    Steps

    Clear a route from a map.

    Create a String that configures the clear attribute to be the id of the location document that contains the route information.

    String document = "<lbs clear='WatRoute'></lbs>";

    Clear all routes from a map.

    Create a String that configures the clear attribute to be ROUTES.

    String document = "<lbs clear='ROUTES'></lbs>";

    Clear all routes and location information from a specific location documents with an id attribute.

    Create a String that configures the clear attribute to be DOCS.

    String document = "<lbs clear='DOCS'></lbs>";

    Clear all routes and location information from a map.

    Create a String that configures the clear attribute to be ALL.

    String document = "<lbs clear='ALL'></lbs>";
    Clearing map content occurs before any new map content is displayed on the map. You can combine the actions of displaying and clearing map content into one location document.
    String document = "<lbs clear='WatRoute' id='NewRoute'><getRoute>
        <location x='-8051111' y='4341111'
           label='NewRoute #1' description='New Route #1' />
        <location x='-7562222' y='4542222'
           label='NewRoute #2' description='New Route #2' />
        </getRoute></lbs>";
    

Code sample: Displaying a route using a location document

import net.rim.blackberry.api.invoke.*;

public class invokeMaps
{
    public invokeMaps ()
    {
        String document = "<lbs id='WatRoute'><getRoute>
            <location x='-8052237' y='4346518'
              label='Waterloo, ON' description='Waterloo, Ontario, Canada' />
            <location x='-7569792' y='4542349'
              label='Ottawa, ON' description='Ottawa, Ontario, Canada' />
            </getRoute></lbs>";
        Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments
            (MapsArguments.ARG_LOCATION_DOCUMENT, document));
    }
}

Was this information helpful? Send us your comments.