2009-09-07 10 views

Respuesta

9

Recientemente tuve la idea de usar Google Maps website desde Browser.Field pero no es posible porque GMaps está basado en JavaScript y es mal soportado por el navegador nativo de Blackberry.

En realidad hay 2 maneras de usar Google Maps en Blackberry:

0

Aquí hay un pequeño ejemplo:

El formulario para ver la imagen de Google Maps estática:

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

} 

La clase clase INET para descargar la estática imagen:

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

La acción de botón que inicia la descarga y la acción de devolución de llamada que carga el formulario para ver la imagen

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

Refina y edita el código para que se ajuste a tus necesidades. Me tomó un tiempo para hacerlo bien.

0

Ahora es posible utilizar Google Maps en lugar de mapas de BlackBerry con nuestros propios datos, como en la imagen. enter image description here

Si usted está mirando para utilizar los mapas de Google para mostrar sus propias ubicaciones/marcadores puede invocar los mapas de Google utilizando ApplicationDescriptor desde la aplicación. Compruebe si hay mapas de Google en el dispositivo usando CodeModuleManager.getModuleHandle("GoogleMaps");. Devuelve un número entero donde no cero significa que está disponible. Luego puede agregar ubicaciones en su archivo KML, incluso puede personalizar punteros de ubicación usando etiquetas de archivos KML.

El example como ligado por Max permite que un solo marcador solamente. Por lo tanto, se necesita un archivo KML si se van a agregar marcadores múltiples.

Puede consultar el sencillo tutorial here para principiantes.

Cuestiones relacionadas