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

You can use a location document to display a location on a map in BlackBerry® Maps. You can also clear locations from a map after they are displayed.
  1. Import the required classes.
    import net.rim.blackberry.api.invoke.*;
  2. Create a class and a 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> element. Configure a <location> element with the location that you want to display.
    String document = "<lbs id='Waterloo'>
         <location x='-8052237' y='4346518'
            label='Waterloo, ON' description='Waterloo' zoom='10' />
         </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 location 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 location information from a map after it has been displayed :

    Task

    Steps

    Clear a location from a map.

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

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

    Clear all locations from a map.

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

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

    Clear all locations and routes 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='Waterloo' id='NewZone'>
         <location x='-8050000' y='4340000'
            label='NewZone' description='NewZone' zoom='10' />
         </lbs>";
    

Code sample: Displaying locations on a map by using a location document

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

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

Was this information helpful? Send us your comments.