2012-12-19 23 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函数等待更新映射,然后继续使用标记。