0

Many Blackberry applications now use Google Maps (dynamic). How it is done?

Is any open source code available? In a related answer it says to use Google Static Maps API to generate and send images upon device request. This will require server-side implementation.

How it will implement using this method?

Community
  • 1
  • 1
Ajmal M A
  • 1,546
  • 1
  • 20
  • 43

1 Answers1

1
**GMLocation.java**
package com.mycroxley.global;

import net.rim.blackberry.api.browser.Browser;
import net.rim.blackberry.api.browser.BrowserSession;
import net.rim.blackberry.api.browser.URLEncodedPostData;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.ApplicationManagerException;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.CodeModuleManager;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiEngine;
import net.rim.device.api.ui.component.Dialog;

public class GMLocation {
    String mName;
    String mDescription;
    double mLatitude;
    double mLongitude;
    public GMLocation(double lat, double lon) {
        mLatitude = lat;
        mLongitude = lon;
    }    
    public GMLocation(double d, double e, String name) {
        this(d, e);
        mName = name;
    }    
    public GMLocation(double lat, double lon, String name, String descr) {
        this(lat, lon, name);
        mDescription = descr;
    }    
    public String getName() {
        return mName;
    }    
    public String getDescription() {
        return mDescription;
    }    
    public String getLongitude() {
        return String.valueOf(mLongitude);
    }    
    public String getLatitude() {
        return String.valueOf(mLatitude);
    }

    public void invokeGMaps(GMLocation l) 
    {
        int mh = CodeModuleManager.getModuleHandle("GoogleMaps");
        if (mh == 0)
        {
            try 
            {   
                Object[] choices = new Object[] {"Download", "Cancel"};

                int result = Dialog.ask("GMap Not Installed", choices, 0);

                switch (result)
                {
                    case 0:
                    BrowserSession visit = Browser.getDefaultSession();
                    visit.displayPage("http://m.google.com/maps");
                    break;

                    case 1:
                    break;
                    default:
                }
            } 
            catch (Exception e) 
            {
                System.out.println(e.getMessage());
            }
        }
        else
        {
            URLEncodedPostData uepd = new URLEncodedPostData(null, false);
            uepd.append("action", "LOCN");
            uepd.append("a", "@latlon:" + l.getLatitude() 
                    + "," + l.getLongitude());
            uepd.append("title", l.getName());
            uepd.append("description", l.getDescription());
            String[] args = { "http://gmm/x?" + uepd.toString() };
            ApplicationDescriptor ad = CodeModuleManager
            .getApplicationDescriptors(mh)[0];
            ApplicationDescriptor ad2 = new ApplicationDescriptor(ad, args);
            try {
                ApplicationManager.getApplicationManager()
                .runApplication(ad2, true);
            } catch (ApplicationManagerException e) {
                System.out.println(e.getMessage());
            }
        }
    }

}

Use this type For show location on GoogleMap

GMLocation location = new GMLocation(Double.parseDouble("18.646245142670608"), Double.parseDouble("18.646245142670608"),"Niger");
location.invokeGMaps(location); 
Parag Chauhan
  • 34,968
  • 13
  • 85
  • 95
  • thnks for replay. i want to use google map in my application without installing google map application. is there any way? – Ajmal M A Nov 12 '11 at 05:57