在 Blackberry 应用程序中使用 Google 地图

发布于 2024-08-03 20:23:46 字数 38 浏览 8 评论 0 原文

谁能告诉我如何在黑莓应用程序开发中使用谷歌地图而不是黑莓地图?

Can anyone tell me how to use Google maps in blackberry application development instead of Blackberry map?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的他你的她 2024-08-10 20:23:46

最近,我想到使用 Google 地图网站 /en/developers/deliverables/8540/Display_content_in_BB_Browser_field_565587_11.jsp" rel="noreferrer">Browser.Field 但这是不可能的,因为 GMaps 基于 JavaScript 并且黑莓本机浏览器对其支持很差。

实际上,在 Blackberry 上使用 Google 地图有 2 种方法:

Recently I had an idea to use Google Maps website from Browser.Field but it's not possible since GMaps are based on JavaScript and it's badly supported by Blackberry native Browser.

Actually there are 2 ways of using Google Maps on Blackberry:

萌无敌 2024-08-10 20:23:46

下面是一个小例子:

查看 Google 地图静态图像的表单:

public class frmMap extends Form implements CommandListener {

    Command _back;
    MIDlet midlet;
    Form dis;

    public frmMap(String title, ImageItem img, MIDlet m, Form d){
        super(null);

        this.midlet = m;
        this.dis = d;

        _back = new Command("Back", Command.BACK, 1);
        addCommand(_back);
        append(img);
        setCommandListener(this);        
    }

    public void commandAction(Command c, Displayable d) {
        if(c == _back){
            Display.getDisplay(midlet).setCurrent(dis);
        }
    }

}

下载静态图像的 inet 类:

public class INETclass implements Runnable {

    private String _location = null;
    private HttpConnection inet;
    private Pispaal _m;
    public String url = null;

    public INETclass(String location, Pispaal m){
        _location = location;
        _m = m;        
    }

    public void run() {
        try
        {
            //Setup the connection
            inet = (HttpConnection)Connector.open(url);
            inet.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            int rc = inet.getResponseCode();

            //Responsecode controleren
            if(rc == HttpConnection.HTTP_OK){
                //Open input stream to read the respone
                DataInputStream is = new DataInputStream(inet.openInputStream());                
                StringBuffer sb = new StringBuffer();

                int ch;
                long len = -1;
                byte[] buffer = null;
                if(_location == null){
                    len = is.available();
                }

                if(len != -1){
                    if(_location == null){
                        buffer = IOUtilities.streamToBytes(is);
                    }else{
                        while((ch = is.read()) != -1){
                            sb.append((char)ch);
                        }
                    }
                }
                is.close();

                if(_location == null){
                    _m.OnINETComplete(buffer);
                }else{
                    _m.Alert(sb.toString());
                }
            }else{
                _m.Alert("URL " + url + " geeft response code: " + rc);
                try
                {
                    inet.close();
                }catch(Exception e){
                    _m.Alert("Error: " + e.getMessage());
                }
            }

        }
        catch(Exception e)
        {
            _m.Alert("Error: " + e.getMessage());
            System.out.println("Error: " + e.getMessage());
        }
        finally
        {
            try
            {
                if(inet != null){ inet.close(); }  
                Thread.currentThread().join(); //Making sure this thread dies
            }catch(Exception e){
                _m.Alert("Error: " + e.getMessage());
                System.out.println("Error: " + e.getMessage());
            }
        }
    }
}

启动下载的 Button 操作和加载表单以查看图像的回调

public void commandAction(Command c, Displayable d) {
        synchronized(c){
            String loc = _location.getText();
            if(loc.indexOf(",") > 0){
                //if(c == _strCommand){                
                    //INETclass inet = new INETclass(loc, this);
                    //Thread tInet = new Thread(inet);
                    //tInet.start();
                    //Alert("Locatie word doorgestuurd. Even geduld");
                //}else 
                if(c == _mapView){
                    INETclass inet = new INETclass(null, this);
                    inet.url = "http://www.qeueq.com/gmap.php?location=" + this.lat + "," + this.lon + "&size=" + this.width + "x" + this.height + ";deviceside=true";
                    Thread tInet = new Thread(inet);
                    tInet.start();
                }
            }else{
                Alert("GPS locatie is nog niet beschikbaar.");
            }
        }
    }

public void UpdateLocation(double lat, double lon){
       String location = lat + "," + lon;
       this.lat = lat;
       this.lon = lon;
       synchronized(location){
           _location.setText(location);
            INETclass inet = new INETclass(location, this);
            Thread tInet = new Thread(inet);
            tInet.start();           
       } 
    }

操作 精炼和编辑代码所以它适合您的需求。我花了一些时间才把它弄好。

Here is a little example:

The Form to view the Google Maps Static image:

public class frmMap extends Form implements CommandListener {

    Command _back;
    MIDlet midlet;
    Form dis;

    public frmMap(String title, ImageItem img, MIDlet m, Form d){
        super(null);

        this.midlet = m;
        this.dis = d;

        _back = new Command("Back", Command.BACK, 1);
        addCommand(_back);
        append(img);
        setCommandListener(this);        
    }

    public void commandAction(Command c, Displayable d) {
        if(c == _back){
            Display.getDisplay(midlet).setCurrent(dis);
        }
    }

}

The class inet class to download the static image:

public class INETclass implements Runnable {

    private String _location = null;
    private HttpConnection inet;
    private Pispaal _m;
    public String url = null;

    public INETclass(String location, Pispaal m){
        _location = location;
        _m = m;        
    }

    public void run() {
        try
        {
            //Setup the connection
            inet = (HttpConnection)Connector.open(url);
            inet.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            int rc = inet.getResponseCode();

            //Responsecode controleren
            if(rc == HttpConnection.HTTP_OK){
                //Open input stream to read the respone
                DataInputStream is = new DataInputStream(inet.openInputStream());                
                StringBuffer sb = new StringBuffer();

                int ch;
                long len = -1;
                byte[] buffer = null;
                if(_location == null){
                    len = is.available();
                }

                if(len != -1){
                    if(_location == null){
                        buffer = IOUtilities.streamToBytes(is);
                    }else{
                        while((ch = is.read()) != -1){
                            sb.append((char)ch);
                        }
                    }
                }
                is.close();

                if(_location == null){
                    _m.OnINETComplete(buffer);
                }else{
                    _m.Alert(sb.toString());
                }
            }else{
                _m.Alert("URL " + url + " geeft response code: " + rc);
                try
                {
                    inet.close();
                }catch(Exception e){
                    _m.Alert("Error: " + e.getMessage());
                }
            }

        }
        catch(Exception e)
        {
            _m.Alert("Error: " + e.getMessage());
            System.out.println("Error: " + e.getMessage());
        }
        finally
        {
            try
            {
                if(inet != null){ inet.close(); }  
                Thread.currentThread().join(); //Making sure this thread dies
            }catch(Exception e){
                _m.Alert("Error: " + e.getMessage());
                System.out.println("Error: " + e.getMessage());
            }
        }
    }
}

The Button action that starts the download and the callback action that loads the form to view the image

public void commandAction(Command c, Displayable d) {
        synchronized(c){
            String loc = _location.getText();
            if(loc.indexOf(",") > 0){
                //if(c == _strCommand){                
                    //INETclass inet = new INETclass(loc, this);
                    //Thread tInet = new Thread(inet);
                    //tInet.start();
                    //Alert("Locatie word doorgestuurd. Even geduld");
                //}else 
                if(c == _mapView){
                    INETclass inet = new INETclass(null, this);
                    inet.url = "http://www.qeueq.com/gmap.php?location=" + this.lat + "," + this.lon + "&size=" + this.width + "x" + this.height + ";deviceside=true";
                    Thread tInet = new Thread(inet);
                    tInet.start();
                }
            }else{
                Alert("GPS locatie is nog niet beschikbaar.");
            }
        }
    }

public void UpdateLocation(double lat, double lon){
       String location = lat + "," + lon;
       this.lat = lat;
       this.lon = lon;
       synchronized(location){
           _location.setText(location);
            INETclass inet = new INETclass(location, this);
            Thread tInet = new Thread(inet);
            tInet.start();           
       } 
    }

Refine and edit the code so it fits your needs. Took me some time to get it right.

榕城若虚 2024-08-10 20:23:46

现在可以使用 Google 地图而不是 BlackBerry 地图以及我们自己的数据(如图所示)。
在此处输入图像描述

如果您希望使用谷歌地图来显示您自己的位置/标记,您可以使用以下命令调用谷歌地图来自您的应用程序的 ApplicationDescriptor。使用 CodeModuleManager.getModuleHandle("GoogleMaps") 检查设备上的 google 地图; 它返回一个整数,其中非零表示可用。然后,您可以在 KML 文件中添加位置,甚至可以使用 KML 文件标签自定义位置指针。

示例 由 Max 链接仅允许单个标记。因此,如果要添加多个标记,则需要 KML 文件。

您可以查看简单的教程 这里适合初学者。

It is possible now to use Google Maps instead of BlackBerry maps with our own data like in the image.
enter image description here

If you're looking to use google maps to show your own locations/markers you can invoke google maps using ApplicationDescriptor from your application. Check for google maps on device using CodeModuleManager.getModuleHandle("GoogleMaps"); it returns an integer where non zero means it is available. Then you can add locations in your KML file, you can even customize location pointers using KML file tags.

The example as linked by Max allows a single marker only. So a KML file becomes necessary if multiple markers are to be added.

You may look at the simple tutorial here for beginners.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文