2010-11-22 6 views
2

J'essaie d'obtenir les limites de ma mapview mais j'ai eu le problème que la latitude est toujours définie sur 0 et longtitude est toujours définie sur 360 * 1E6. Selon ce lien, c'est parce qu'il n'offrira le droit coordonnées lorsque la carte est entièrement chargée: Mapview getLatitudeSpan and getLongitudeSpan not workingMapView latitudeSpan/longtitudeSpan ne fonctionne pas

Maintenant, je suis tout à fait confus au sujet de la solution, je fis cette méthode que j'appelle de la onCreate de mon Mainactivity (the mapview):

public int[][] getBounds() 
{ 
GeoPoint center = this.mapView.getMapCenter(); 
int latitudeSpan = this.mapView.getLatitudeSpan(); 
int longtitudeSpan = this.mapView.getLongitudeSpan(); 
int[][] bounds = new int[2][2]; 

bounds[0][0] = center.getLatitudeE6() + (latitudeSpan/2); 
bounds[0][1] = center.getLongitudeE6() + (longtitudeSpan/2); 

bounds[1][0] = center.getLatitudeE6() - (latitudeSpan/2); 
bounds[1][1] = center.getLongitudeE6() - (longtitudeSpan/2); 
return bounds; 
} 

Comment puis-je faire attendre le chargement de la carte? J'ai regardé dans l'API pour postDelayed, mais je n'arrive pas à le faire fonctionner.

Pardonnez-moi si je suis o.o stupide

Répondre

3

La bonne façon de créer un "Timer" dans Android est d'utiliser android.os.Handler:

private Handler updateHandler = new Handler(); 

updateHandler.postDelayed(waitForMapTimeTask, TIME_TO_WAIT_IN_MS); 

private Runnable waitForMapTimeTask = new Runnable() { 
    public void run() { 
     getBounds(); 
     // Read the bounds to see if something reasonable is returned 
     if (!mapIsLoaded) { 
      updateHandler.postDelayed(waitForMapTimeTask, TIME_TO_WAIT_IN_MS); 
     } 
    } 
}; 
+0

Merci qui a travaillé comme un charme :) – shokora