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.
  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.invoke.*;
    import javax.microedition.pim.*;
  2. Create a class and constructor to use to invoke BlackBerry Maps.
    public class invokeMaps
    {
        public invokeMaps ()
        {
        }
    }
  3. In the constructor, retrieve an instance of a ContactList object from the BlackBerry device. Create a contact by using 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";
  4. 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);

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

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

public class invokeMaps
{
    public invokeMaps()
    {
        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";

        MapsArguments mapsArgs = new MapsArguments(contact, 0);
        Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, mapsArgs);
    }
}

Was this information helpful? Send us your comments.