【发布时间】:2016-04-26 20:09:23
【问题描述】:
我对谷歌地图 api 有疑问。我想要做的是将相机与 Location 一起移动,以便蓝色指示器始终位于中心。
认为放置代码的好地方是在 OnLocationChanged 方法中,但事实并非如此。
我试图在那里运行这段代码:
LatLng latlng = new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latlng,17);
mMap.animateCamera(cameraUpdate);
更新
那么我不能这样做吗?
@Override
public void onLocationChanged(Location location) {
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
.setInterval(10 * 1000)
.setFastestInterval(1 * 1000);
LatLng latLng = new LatLng(location.getLatitude(),location.getLongitude());
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng)
.zoom(ZOOM)
.bearing(0)
.tilt(0)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
【问题讨论】:
-
这是另一个线程的解决方案:stackoverflow.com/questions/13742551/…
-
为什么我不能将以下内容添加到 OnLocationChanged 事件中。:: @Override public void onLocationChanged(Location location) { mLocationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY) .setInterval(10 * 1000) .setFastestInterval(1 * 1000); mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()))); }
-
蓝色指示器位置请求是由地图实现的,与您的位置请求相比,它可以在不同的时间间隔给出不同的点。 AFAIK,无法收听地图使用的默认位置提供程序,您需要顺利更新地图摄像头位置。
-
好的,所以我不能按照我的更新@PabloBaxter 下的代码中显示的那样做
标签: google-maps camera location