Tuesday, April 3, 2012

Invoking Google Map From BlackBerry Applications

Google Maps can be invoked as an application from blackberry applications. For that we need to first download Google Maps and then use the following code to invoke google maps as an application:

   /**
     * Starts the Google Maps application and the specified locatin is shown on map
     * @param latitude the latitude of the location to show
     * @param longitude the longitude of the location to show
     * @param title the title of the location to show
     * @param description the description of the location to show
     */
    public void showGoogleMap(double latitude, double longitude, String title,  String description) {
        try {
            int mh = CodeModuleManager.getModuleHandle("GoogleMaps");
            if (mh == 0) {
                 throw new ApplicationManagerException("GoogleMaps isn't installed");
            }
            URLEncodedPostData uepd = new URLEncodedPostData(null, false);
            uepd.append("action","LOCN");
            uepd.append("a", "@latlon:"+latitude+","+longitude);
            uepd.append("title", title);
            uepd.append("description", description);
            String[] args = { "http://gmm/x?"+uepd.toString() };
            ApplicationDescriptor ad = CodeModuleManager.getApplicationDescriptors(mh)[0];
            ApplicationDescriptor ad2 = new ApplicationDescriptor(ad, args);
            ApplicationManager.getApplicationManager().runApplication(ad2, true);
        } catch(final Exception excp) {
            Dialog.alert("Sorry, can't start Google Map: " + excp.getMessage());
        }
    }

For more info, see this StackOverflow Answer.

No comments:

Post a Comment