Help Center

Local Navigation

Open BlackBerry Maps to display the location for an address in the contact list

You can create a BlackBerry® Application that displays a map for the address of a contact in the contact list. The address for the contact must be a valid address.
  1. Import the following classes:
    • javax.microedition.pim.PIM
    • net.rim.blackberry.api.invoke.Invoke
    • net.rim.blackberry.api.invoke.MapsArguments
    • javax.microedition.pim.PIMException
  2. Import the following interfaces:
    • javax.microedition.pim.Contact
    • javax.microedition.pim.ContactList
    • java.util.Enumeration
  3. Implement the following interfaces:
    • javax.microedition.pim.Contact
    • javax.microedition.pim.ContactList
    • java.util.Enumeration
  4. Create a Contact object.
    Contact c = null;
  5. In a try block, retrieve the contact list.
    try {
    ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
    
  6. Place the items from the contact list into an enumeration.
    Enumeration enumContact = contactList.items();
    int notFinished   = 1;
    
  7. Create a While loop to iterate through all of the items in the enumeration.
    while ((enumContact.hasMoreElements())  && ( notFinished == 1)) {
    c = (Contact)enumContact.nextElement();
    int[]   fieldIds = c.getFields();
    int     id; 
    
  8. Search for the first contact that contains a valid city and region in the contact list, and display the address information for the contact in BlackBerry® Maps.
    if (c.countValues(Contact.ADDR) > 0) {
    String address[] = c.getStringArray(Contact.ADDR,0);
    if ((address[Contact.ADDR_LOCALITY] != null) && (address[Contact.ADDR_REGION] != null)) {
      Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(c,0)); 
                  notFinished = 0;
                }
            }
         }
    } catch (PIMException e) { 
        } 
    
  9. If a contact address is not found, display the default map in BlackBerry Maps.
    if  c == null) {
    Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments());
                            }
                }
    };
    

Was this information helpful? Send us your comments.