Help Center
Local Navigation
- GPS location information
-
BlackBerry Maps location information
- Opening BlackBerry Maps
- Opening BlackBerry Maps from an application
-
Displaying location information on a BlackBerry device
- Displaying location information in BlackBerry Maps
- Open BlackBerry Maps to display the default map view
- Open BlackBerry Maps to display a location on a map
- Open BlackBerry Maps to display multiple locations on a map
- Open BlackBerry Maps to display a route between locations on a map
- Open BlackBerry Maps to display a custom map view
- Open BlackBerry Maps to display the location for an address in the contact list
- Start a BlackBerry device application from BlackBerry Maps
- Displaying location information in a UI field
- Requesting location information for an address
- Open BlackBerry Maps from a browser
- Clearing data from the map
- Resources
- Glossary
- Provide feedback
- Legal notice
BlackBerry Manuals & Help
>
Documentation for Developers
>
Java Development Guides and API Reference
>
GPS and BlackBerry Maps - Development Guide - BlackBerry Java Development Environment - 4.7.0
Start a BlackBerry device application from BlackBerry Maps
You can add a menu item to BlackBerry® Maps that permits a BlackBerry
device user to start a BlackBerry
device application using location information. The BlackBerry
device
user can also change location information and send the information to the BlackBerry
device application.
- Open the BlackBerry® Integrated Development Environment.
- Create a project.
- Right-click the project and click Properties.
- On the Applications tab, in the Arguments passed to field, type startup . Make sure that the value you type matches the value in the startsWith argument in the main method of the BlackBerry device application.
- Select Auto-run on startup.
- Select System module.
- Click OK.
- Import the following classes:
import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.blackberry.api.invoke.*; import net.rim.device.api.system.*; import net.rim.blackberry.api.maps.*; import net.rim.blackberry.api.menuitem.*;
- Create a class that extends the ApplicationMenuItem class and implements the run() and toString() methods.
private static class MapsMenuItem extends ApplicationMenuItem { MapsMenuItem() { super(20); } public String toString() { return "Menu Item Demo"; } public Object run(Object context) { if (context instanceof MapView ) { _mv = (MapView)context; UiApplication app = UiApplication.getUiApplication(); app.pushScreen( new MapsMenuItemScreen(_mv) ); app.requestForeground(); } return null; } } } - In the main() method, register a menu item with BlackBerry Maps.
public static void main(String[] args) { if (args != null && args.length > 0) { if (args[0].equals("startup")) { ApplicationMenuItemRepository amir = ApplicationMenuItem Repository.getInstance(); ApplicationDescriptor artup = ApplicationDescriptor .currentApplicationDescriptor(); ApplicationDescriptor ad_gui = new ApplicationDescriptor (ad_startup , "gui", new String[]{"gui"}); amir.addMenuItem(ApplicationMenuItemRepository. MENUITEM_MAPS , new MapsMenuItem() , ad_gui); } else if (args[0].equals("gui")) { MapsMenuItemDemo app = new MapsMenuItemDemo(); app.enterEventDispatcher(); } } } - Create a screen for the application.
final class MapsMenuItemScreen extends MainScreen { private MapView _mapview; private BasicEditField _latitudeField; private BasicEditField _logitudeField; private NumericChoiceField _zoomField; MapsMenuItemScreen(MapView _mv) { _mapview = _mv; _latitudeField = new BasicEditField ("Latitude: " , _mv.getLatitude() /100000.0 + "" , 9 , BasicEditField.FILTER_REAL_NUMERIC ); _logitudeField = new BasicEditField ("Longitude: ",_mv.getLongitude() /100000.0 + "" , 10 , BasicEditField.FILTER_REAL_NUMERIC); _zoomField = new NumericChoiceField ("Zoom: " , 0 , MapView.MAX_ZOOM , 1 , _mv.getZoom()); add(_latitudeField); add(_logitudeField); add(_zoomField); add(new SeparatorField()); add(new RichTextField("Edit latitude, longitude and zoom level settings and select View Map from the menu." , Field.NON_FOCUSABLE)); addMenuItem(viewMapItem); setTitle("Location Details Screen"); } - Create a menu item that displays the latitude, longitude, and zoom values from the MapView context object.
private MenuItem viewMapItem = new MenuItem("View Map", 1000, 10) { public void run() { _mapview.setZoom( _zoomField.getSelectedValue() ); try { int latitude = (int) (100000 * Double.parseDouble (_latitudeField.getText())); int longitude = (int) (100000 * Double.parseDouble (_logitudeField.getText())); if (latitude > 9000000 || latitude < -9000000 || longitude >= 18000000 || longitude < -18000000) { throw new IllegalArgumentException (); } _mapview.setLatitude(latitude); _mapview.setLongitude(longitude); Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(_mapview)); close(); } catch(RuntimeException re) { Dialog.alert("Invalid Longitude and/or Latitude"); _latitudeField.setFocus(); } } }; - Populate the menu.
protected void makeMenu( Menu menu, int instance ) { super.makeMenu( menu, instance ); if(getFieldWithFocus() == _zoomField) { menu.setDefault(1); } }
Previous topic: View a sample application that displays the location for an address in the contact list