2009-09-07 15 views

risposta

9

Recentemente ho avuto un'idea di utilizzare Google Maps website da Browser.Field ma non è possibile poiché le GMaps si basano su JavaScript ed è mal supportato dal browser nativo di Blackberry.

In realtà ci sono 2 modi di utilizzo di Google Maps su Blackberry:

0

Ecco un piccolo esempio:

il modulo per visualizzare l'immagine Google Maps Statico:

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 classe classe INET per scaricare la statica immagine:

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

L'azione Pulsante che avvia il download e l'azione di callback che carica il modulo per visualizzare l'immagine

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

Affinare e modificare il codice in modo che soddisfi le vostre esigenze. Mi ci è voluto un po 'di tempo per farlo bene.

0

È ora possibile utilizzare Google Maps anziché le mappe BlackBerry con i nostri dati come nell'immagine. enter image description here

Se stai cercando di utilizzare le mappe di Google per mostrare i propri percorsi/marcatori è possibile richiamare le mappe di Google utilizzando ApplicationDescriptor dalla vostra applicazione. Controlla Google Maps sul dispositivo utilizzando CodeModuleManager.getModuleHandle("GoogleMaps"); restituisce un numero intero in cui non zero significa che è disponibile. Quindi puoi aggiungere posizioni nel tuo file KML, puoi persino personalizzare i puntatori di posizione utilizzando i tag di file KML.

Il example come legata da Max consente solo un singolo marcatore. Quindi un file KML diventa necessario se si devono aggiungere più marcatori.

Si può guardare il semplice tutorial here per principianti.