【问题标题】:Use Google Map in Blackberry application在黑莓应用程序中使用谷歌地图
【发布时间】:2013-05-28 23:31:05
【问题描述】:

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

【问题讨论】:

    标签: google-maps blackberry gps jsr179


    【解决方案1】:

    最近我有一个想法,使用 Browser.Field 中的 Google Maps website,但这是不可能的,因为 GMaps 是基于 JavaScript 的,而且黑莓原生浏览器对它的支持很差。

    其实在黑莓上使用谷歌地图有两种方式:

    【讨论】:

      【解决方案2】:

      这是一个小例子:

      查看谷歌地图静态图片的表单:

      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();           
             } 
          }
      

      优化和编辑代码,使其符合您的需求。我花了一些时间才把它弄好。

      【讨论】:

        【解决方案3】:

        现在可以使用谷歌地图而不是黑莓地图来处理我们自己的数据,如图所示。

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

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

        你可以看看初学者的简单教程here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多