2014-08-29 67 views
1

我正在開發一個Android應用程序,用於跟蹤從當前位置到特定目的地的路徑。它運作良好。但有一個例外情況。Google地圖不會移動到新的LatLng位置

當用戶點擊目標標記時,它需要將地圖移動到另一個具有縮放的位置。但只有在不移動到第二個位置的情況下才能放大。

這是我的相關代碼段。如果你可以請幫我這個。提前致謝。

double Kumana1_Latitude = 6.573022; 
double Kumana1_Longitude = 81.666875; 

double Kumana2_Latitude = 6.649353; 
double Kumana2_Longitude = 81.770114; 


final LatLng Kumana = new LatLng(Kumana1_Latitude, Kumana1_Longitude); 
final LatLng Kumana2 = new LatLng(Kumana2_Latitude,Kumana2_Longitude); 

Marker Kumana_marker = mGoogleMap.addMarker(new MarkerOptions() 
    .title("Kumana National Park") 
    .icon(BitmapDescriptorFactory 
    .defaultMarker(BitmapDescriptorFactory.HUE_GREEN)) 
    .position(Kumana)); 
    Kumana_marker.showInfoWindow(); 

    mGoogleMap.setOnMarkerClickListener(new OnMarkerClickListener() { 

       @Override 
       public boolean onMarkerClick(Marker m) { 

       //here it get Zoomed, but does not move to the new location 
       mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Kumana2, 13)); 

       m.remove(); 
       Toast.makeText(getApplicationContext(), 
       "Tap on the Kumana National Park entreance", Toast.LENGTH_LONG) 
       .show(); 
    }); 

      }  
+0

你嘗試用'animateCamera'? https://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html#animateCamera(com.google.android.gms.maps.CameraUpdate) – fasteque 2014-08-29 10:10:36

回答

0

試圖調用super.onMarkerClick(m)在被覆蓋的功能ònMarkekClick(標記M)`。

2

將標記放入onLocationChanged()並繪製標記。首先刪除標記,然後將新標記添加到新位置。

所有這些代碼必須來自下onLocationChanged() 首先檢查

(if marker == null){ 
//plot marker 
} 
else{ 
//remove first marker.. 
//add new marker 
} 
+0

對於縮進感到抱歉.. :(我是新的這個stackoverflow的東西.. – Nevermore 2015-02-23 06:03:16

+0

http://stackoverflow.com/help/formatting這裏:) – Patrice 2015-02-23 06:19:48

+0

@Patrice謝謝你!非常感謝。 – Nevermore 2015-02-23 06:29:17