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.
- Import the following classes:
- javax.microedition.pim.PIM
- net.rim.blackberry.api.invoke.Invoke
- net.rim.blackberry.api.invoke.MapsArguments
- javax.microedition.pim.PIMException
- Import the
following interfaces:
- javax.microedition.pim.Contact
- javax.microedition.pim.ContactList
- java.util.Enumeration
- Implement the
following interfaces:
- javax.microedition.pim.Contact
- javax.microedition.pim.ContactList
- java.util.Enumeration
- Create a Contact object.
Contact c = null;
- In a try block, retrieve the contact list.
try {
ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
- Place the items from the contact list into an enumeration.
Enumeration enumContact = contactList.items();
int notFinished = 1;
- 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;
- 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) {
}
- 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.