4

我的应用程序显示用户的驾驶路线。几秒钟后,地图停止加载新内容,如下所示: 在此处输入图像描述

我的代码: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>

爪哇:

            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);

有没有办法使地图无效?

谢谢你的帮助!

4

3 回答 3

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));
}
于 2012-12-23T11:39:40.277 回答
0

Use Thread.sleep(300); after updating the map with markers, overlays, etc. Google Maps uses its own internal threads and need time to apply changes. It is possible that the thread adding stuff to the map is blocking Google Map's thread. The sleep will give it some time to make the update.

于 2013-07-18T15:00:37.030 回答
0

我不知道有没有,直到你有问题。但我解决了,我想和你分享。您可以使用处理程序和 Thread.sleep(600)。如果你只使用处理程序,你会遇到同样的问题。Thread.sleep 函数等待更新地图,然后继续标记。

于 2014-08-18T19:14:52.510 回答