2013-01-16 103 views
1

有一個谷歌MapView和投影圓圈區域。如果用戶保持在投影圈內部移動,應該彈出消息框,以便我需要偵聽器和投影實現。谷歌地圖視圖投影區域監聽器

我不知道我必須使用哪個聽衆。如果你幫我,我明白這一點。感謝

回答

0

嘗試用它爲你的距離,我認爲:distanceBetween

喲可以實現你的聽衆有一個Runnable:

private Handler handler = new Handler(); 
    public static final int circleCheckingDelay = 1000; // in ms 


    private Runnable circleChecker = new Runnable() 
    { 
     public void run() 
     { 
      float distance= getDistance(GeoPoint p1, GeoPoint p2); 
      if(distance < ...) 
      { 
      //do something 
      } 
      handler.removeCallbacks(circleChecker); 
      handler.postDelayed(circleChecker, circleCheckingDelay); 
     } 
    }; 

添加以下功能在您的mapActivity:

的onResume :

handler.postDelayed(circleChecker, circleCheckingDelay); 

OnPause:

handler.removeCallbacks(circleChecker); 

檢查這個環節太: how to find the distance between two geopoints?

例如函數來獲取的距離:

public float getDistance(GeoPoint p1, GeoPoint p2) { 
    double lat1 = ((double)p1.getLatitudeE6())/1e6; 
    double lng1 = ((double)p1.getLongitudeE6())/1e6; 
    double lat2 = ((double)p2.getLatitudeE6())/1e6; 
    double lng2 = ((double)p2.getLongitudeE6())/1e6; 
    float [] dist = new float[1]; 
    Location.distanceBetween(lat1, lng1, lat2, lng2, dist); 
    return dist[0]; 
} 
+0

它不是一個聽衆 – KSBeyaz

+0

我編輯希望它可以幫助你 –

+0

感謝您的幫助 – KSBeyaz

相關問題