Difference between revisions of "Teams Winter 2011/team1/BlackBerry/Add Mapping Option"

From CDOT Wiki
Jump to: navigation, search
(Created page with '=== 10. Add Mapping Option ===')
 
Line 1: Line 1:
 
=== 10. Add Mapping Option ===
 
=== 10. Add Mapping Option ===
 +
10.1. Add the Map Option to the manu:<br/>
 +
<source lang="java">
 +
  //Show the address on the map
 +
  ImageMenuItem mapItem = new ImageMenuItem("Address on Map", 500, 5, MENU_MAP);
 +
  _mainScreen.addMenuItem(mapItem);
 +
</source>
 +
10.2. Implement address locator:
 +
<source lang="java">
 +
  mapItem.setCommand(new Command(new CommandHandler(){
 +
      public void execute(ReadOnlyCommandMetadata metadata, Object context)
 +
      {
 +
        Student student = (Student) _keywordFilterField.getSelectedElement();
 +
             
 +
        if(student != null)
 +
        {                 
 +
            try
 +
            {                     
 +
              String address = student.getAddress();
 +
              Coordinates co = new Coordinates(45.423488, -75.697929, 0);
 +
              Landmark[] landm = Locator.geocode(address, co);
 +
              double lon = landm[0].getQualifiedCoordinates().getLongitude()*100000.0 ;
 +
              double lat = landm[0].getQualifiedCoordinates().getLatitude()*100000.0;
 +
              StringBuffer document = new StringBuffer("<location-document><location lon='");
 +
              document.append(lon).append("' lat='").append(lat).append("' label='").append(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>

Revision as of 14:13, 7 April 2011

10. Add Mapping Option

10.1. Add the Map Option to the manu:

   //Show the address on the map
   ImageMenuItem mapItem = new ImageMenuItem("Address on Map", 500, 5, MENU_MAP);
   _mainScreen.addMenuItem(mapItem);

10.2. Implement address locator:

   mapItem.setCommand(new Command(new CommandHandler(){
      public void execute(ReadOnlyCommandMetadata metadata, Object context)
      {
         Student student = (Student) _keywordFilterField.getSelectedElement();
               
         if(student != null)
         {                   
            try
            {                       
               String address = student.getAddress();
               Coordinates co = new Coordinates(45.423488, -75.697929, 0);
               Landmark[] landm = Locator.geocode(address, co);
               double lon = landm[0].getQualifiedCoordinates().getLongitude()*100000.0 ;
               double lat = landm[0].getQualifiedCoordinates().getLatitude()*100000.0;
               StringBuffer document = new StringBuffer("<location-document><location lon='");
               document.append(lon).append("' lat='").append(lat).append("' label='").append(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());
             }
            }
          }
     }));