Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Open BlackBerry Maps by using information from a contact

You can open BlackBerry Maps to display a location on a map by using the address information from a contact in the Contacts application on the BlackBerry device.

Code sample: Invoking BlackBerry Maps by using information from a contact

import net.rim.blackberry.api.invoke.*;
import javax.microedition.pim.*;

//Create a class and constructor to use to invoke BlackBerry Maps.
public class invokeMaps
{
    public invokeMaps()
    {

//In the constructor, retrieve an instance of a ContactList object from the BlackBerry
//device. Create a contact with the Contact class. 
//Populate the Contact with the name and address of the contact.
        ContactList contacts = null;

        try
        {
            contacts = (ContactList) PIM.getInstance().openPIMList
             (PIM.CONTACT_LIST, PIM.READ_ONLY);
        }
        catch (PIMException e)
        {
            return;
        }

        Contact contact = contacts.createContact();

        contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE,
          "Ms. Andrea Aime");
        contact.addString(Contact.FORMATTED_ADDR, PIMItem.ATTR_NONE,
          "455 Phillip St. Waterloo ON N2L3X2 Canada");

        String[] name = new String[ contacts.stringArraySize( Contact.NAME ) ];
        name[ Contact.NAME_GIVEN ] = "Andrea";
        name[ Contact.NAME_FAMILY ] = "Aime";
        name[ Contact.NAME_PREFIX ] = "Ms.";

        String[] addr = new String[ contacts.stringArraySize( Contact.ADDR ) ];
        addr[ Contact.ADDR_STREET ] = "455 Phillip St";
        addr[ Contact.ADDR_LOCALITY ] = "Waterloo";
        addr[ Contact.ADDR_REGION ] = "ON";
        addr[ Contact.ADDR_POSTALCODE ] = "N2L3X2";
        addr[ Contact.ADDR_COUNTRY ] = "Canada";

//In the constructor, create a MapsArguments object by passing in the Contact 
//object with an offset of zero. Invoke  Invoke.invokeApplication()  to open 
//BlackBerry Maps. Pass in the MapsArguments object.
        MapsArguments mapsArgs = new MapsArguments(contact, 0);
        Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, mapsArgs);
    }
}