如何移动 google 地图以及周期性移动的标记

How to Move google Map along with periodically moving marker

我正在开发 google 地图应用程序,我在其中设置了 google 地图和移动车辆的标记。我从 API 获取纬度和经度,并定期(每 25 秒)更新 google 地图上的标记。

         When updating marker I am unable to move the google map along with the marker. How to move the google map along with the periodically moving marker.

任何帮助对我来说都是一个很大的帮助。

因此,为了随着标记位置的变化移动地图,您可以这样做:

public void onLocationChanged(Location loc) {
    //some marker movements here...

    CameraPosition currentPlace = new CameraPosition.Builder()
            .target(new LatLng(loc.getLatitude(), loc.getLongitude())
            .tilt(0f)
            .zoom(18)
            .build();

    map.animateCamera(CameraUpdateFactory.newCameraPosition(currentPlace), 200, null);
}

当然,您需要访问 GoogleMap 对象。

以下代码片段说明了移动相机的一些常用方法:

private static final LatLng SYDNEY = new LatLng(-33.88,151.21);
private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1);

private GoogleMap map;
... 

// Obtain the map from a MapFragment or MapView.

// Move the camera instantly to Sydney with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15));

// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomIn());

// Zoom out to zoom level 10, animating with a duration of 2 seconds.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

// Construct a CameraPosition focusing on Mountain View and animate the camera to that position.
CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(MOUNTAIN_VIEW)      // Sets the center of the map to Mountain View
                .zoom(17)                   // Sets the zoom
                .bearing(90)                // Sets the orientation of the camera to east
                .tilt(30)                   // Sets the tilt of the camera to 30 degrees
                .build();                   // Creates a CameraPosition from the builder

map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

基于Documentation for the Android Google Maps API

编辑:

我在 Udacity 上发现了一些关于 Google 地图的有趣课程: