2012-12-19 24 views
4

我的應用顯示用戶的驅動路線。幾秒鐘後,地圖將停止加載新的內容,看起來像這樣: enter image description hereAndroid的谷歌地圖V2犯規刷新

我的代碼: XML

<fragment 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    class="com.google.android.gms.maps.SupportMapFragment" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    map:cameraZoom="19" 
    android:layout_below="@+id/tracking_maps_colorgradient"> 
</fragment> 

的Java:

  float zoom = 18;//googleMap.getCameraPosition().zoom; 
     LatLng latLng = new LatLng(lastLatitude, lastLongitude); 
     locations.add(latLng); 
     CameraPosition pos = new CameraPosition.Builder() 
      .target(latLng) 
      .bearing(bearing) 
      .zoom(zoom) 
      .tilt(googleMap.getCameraPosition().tilt) 
      .build(); 

     googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(pos)); 
     Polyline p = googleMap.addPolyline(new PolylineOptions() 
      .add(latLng) 
      .width(15) 
      .color(Color.RED) 
      .geodesic(true)); 
     p.setPoints(locations); 

有沒有辦法使無效地圖?

感謝您的幫助!

+0

沒有人的想法?我還在掛在這個問題... – iTamp

回答

0

好吧,這誰的人有同樣的問題,繼承人的解決方案。問題是GoogleMap始終刷新,當用戶超出界限時必須更改相機位置。

LatLngBounds bounds = this.googleMap.getProjection().getVisibleRegion().latLngBounds; 

if(!bounds.contains(new LatLng(gps.getLatitude(), gps.getLongitude())))  { 
    //Move the camera to the user's location if they are off-screen! 
    CameraPosition cameraPosition = new CameraPosition.Builder() 
    .target(new LatLng(gps.getLatitude(), gps.getLongitude()))  
    .zoom(zoom)     // Sets the zoom 
    .bearing(bearing) 
    .build();     // Creates a CameraPosition from the builder 
    googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 
} 
+1

更改相機位置可能會導致新的地圖請求,谷歌,並最終從自己的配額中扣除。意識到!儘可能避免使用相機重新定位。 – AndroidDev

0

Use Thread.sleep(300);在使用標記,覆蓋圖等更新地圖之後,Google地圖使用自己的內部線程,並需要時間來應用更改。線程向地圖添加內容可能會阻止Google Map的線程。睡眠會給它一些時間來進行更新。

0

我不知道有,直到你有問題。但我解決了,我想和你分享。 您可以使用處理程序和Thread.sleep(600)。如果你只使用處理程序,你會遇到同樣的問題。 Thread.sleep函數等待更新映射,然後繼續使用標記。