private void invokeMaps( final Object arg ) throws Exception {
MapsArguments args = null;
if( arg instanceof MapsArgumentsObject ) {
final MapsArgumentsObject m = (MapsArgumentsObject) arg;
if( m.isDefault() ) {
args = new MapsArguments();
} else {
// Populate location string from document
final String xml = m.getXML();
if( xml != null ) {
args = new MapsArguments( MapsArguments.ARG_LOCATION_DOCUMENT, xml );
} else {
// Populate location string from address
final AddressObject addressObject = m.getAddressObject();
if( addressObject != null ) {
final String locality = addressObject.getItem( AddressObject.FIELD_CITY ).getStringValue();
final String region = addressObject.getItem( AddressObject.FIELD_STATE ).getStringValue();
if( locality.length() > 0 && region.length() > 0 ) {
Contact c;
// Create a new contact
try {
final ContactList contactList = (ContactList) PIM.getInstance().openPIMList( PIM.CONTACT_LIST,
PIM.READ_WRITE );
c = contactList.createContact();
} catch( final PIMException e ) {
throw e;
}
final String[] addressHome = new String[ 7 ];
addressHome[ Contact.ADDR_STREET ] = addressObject.getItem( AddressObject.FIELD_ADDRESS1 )
.getStringValue();
addressHome[ Contact.ADDR_LOCALITY ] = addressObject.getItem( AddressObject.FIELD_CITY )
.getStringValue();
addressHome[ Contact.ADDR_REGION ] = addressObject.getItem( AddressObject.FIELD_STATE )
.getStringValue();
addressHome[ Contact.ADDR_POSTALCODE ] = addressObject.getItem( AddressObject.FIELD_ZIP )
.getStringValue();
addressHome[ Contact.ADDR_COUNTRY ] = addressObject.getItem( AddressObject.FIELD_COUNTRY )
.getStringValue();
addressHome[ Contact.ADDR_EXTRA ] = addressObject.getItem( AddressObject.FIELD_ADDRESS2 )
.getStringValue();
c.addStringArray( Contact.ADDR, Contact.ATTR_HOME, addressHome );
args = new MapsArguments( c, 0 );
} else {
throw new IllegalArgumentException( "Address should contain 'city' and 'state' information!" );
}
} else {
// Populate location string from coordinate
final long lat = (long) ( m.getLatitude() * 100000 );
final long lon = (long) ( m.getLongitude() * 100000 );
final String locationCoordinate = "<lbs clear='ALL'>" + "<location lon='" + new Long( lon ).toString()
+ "' lat='" + new Long( lat ).toString() + "'/>" + "</lbs>";
args = new MapsArguments( MapsArguments.ARG_LOCATION_DOCUMENT, locationCoordinate );
}
}