【发布时间】:2016-02-26 21:25:06
【问题描述】:
我创建了一个 Android 活动来显示 Google 地图。 我会将地图居中到当前用户位置,但我不知道该怎么做。
这是我当前的代码:
Location location = getMyLocation();
LatLng userPos = new LatLng(location.getLatitude(), location.getLongitude());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(userPos, zoomLevel));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(userPos)
.zoom(17)
.bearing(90)
.tilt(40)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
此代码的来源是 answer(我从中复制了 getMyLocation())和 solution,但它们不起作用。在这两种情况下它都不起作用:中心没有设置,奇怪的是缩放级别也没有设置。
如果我只使用这段代码(没有当前用户位置):
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(42.564241, 12.22759), zoomLevel));
即使设置了缩放级别,它也可以正常工作。
可能是什么问题?
【问题讨论】:
标签: android google-maps dictionary position location