如何在不安装谷歌地图应用程序的情况下将Google Map放入Blackberry应用程序中?

时间:2011-11-12 05:01:21

标签: google-maps blackberry java-me

许多Blackberry应用程序现在都使用谷歌地图(动态)。怎么做的?

是否有可用的开源代码?在一个related answer它说      使用Google Static Maps API根据设备请求生成和发送图片。这将需要服务器端实现。

如何使用此方法实现?

1 个答案:

答案 0 :(得分: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());
            }
        }
    }

}

使用此类型在GoogleMap上显示位置

GMLocation location = new GMLocation(Double.parseDouble("18.646245142670608"), Double.parseDouble("18.646245142670608"),"Niger");
location.invokeGMaps(location);