Changes

Jump to: navigation, search

Teams Winter 2011/team1/BlackBerry/Add Mapping Option

354 bytes added, 21:01, 12 April 2011
no edit summary
=== 10. Add Mapping Option ===
'''*NOTE:''' In order to test this feature the newest version of the simulator must be installed<br/>
10.1. In order to implement Address Locator we need to add address field and getter/setter methods to <code>Student</code> class:
<source lang="java">
}
</source>
10.2. Add EditTextFields to Add, Edit and view option:<br/>
viewItem
<source lang="java">
</source>
addItem
<source lang="java">
EditField inputField4 = new EditField("Student's address: ","");
addDialog.add(inputField4);
{
Student student = (Student) _keywordFilterField.getSelectedElement();
if(student != null) { try { String address = student.getAddress(); //start coordinates Coordinates co = new Coordinates(45.423488, -75.697929, 0); Landmark[] landm = Locator.geocode(address, co); //Get latitude and longitude double lon = landm[0].getQualifiedCoordinates().getLongitude()*100000.0 ; double lat = landm[0].getQualifiedCoordinates().getLatitude()*100000.0; //create XML document StringBuffer document = new StringBuffer("<location-document><location lon='"); document.append(lon).append("' lat='").append(lat).append("' label='").append showAddress(address); document.append("' description='Student Address' zoom='10'/></location-document>"); // Invoke maps application for current Contact Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(MapsArguments.ARG_LOCATION_DOCUMENT, document.toString())); } catch(LocatorException ex){ Dialog.alert("cannot get location: " + ex.getMessage()); } catch(Exception ex){ Dialog.alert("map application is not available: "+ ex.getMessage()); } }
}
} }));
</source>
10.5. Implement <code>showAddress()</code> method. The <code>Locator.geocode()</code?> method must be in another thread:
<source lang="java">
public void showAddress(String adrs)throws LocatorException{
final String address = adrs;
new Thread(new Runnable(){
public void run(){
try {
Landmark[] landm = Locator.geocode(address, null);
MapsArguments ma = new MapsArguments(landm);
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, ma);
} catch (Exception ex) {
Dialog.alert("Exception when getting location: " + ex.getMessage());
}
}
}).start();
}
</source>
10.6. Change the ''Run Configuration ''in order to show maps:<br/>
[[Image: BB_conf1.png | 500px]]<br/>
and<br/>
[[Image: BB_conf2.png | 500px]]<br/>
10.7. Run the application, selected a Student and from the menu select '''Address on Map''':<br/>
 
[[Image: BB_map1.png | 300px]]
[[Image: BB_map2.png | 325px]]
1
edit

Navigation menu