【发布时间】:2014-12-16 21:15:07
【问题描述】:
我正在开发一个使用谷歌地图将用户导航到给定位置的应用程序。我想定位地图,使目标点始终位于地图顶部,当前位置标记位于底部,两个标记在地图中垂直对齐并居中(例如,它们之间的垂直线垂直到屏幕上)
我的方法是找到标记的中点,然后计算方位角以旋转地图,使两个标记最终垂直对齐并居中。将中点居中将使标记居中,但我无法计算出正确的方位值。
任何帮助将不胜感激。
编辑:
我试过Location.bearingTo 和Location.distanceBetween。对于相同的输入,它们返回不同的值,而从Location.distanceBetween 返回的值就是我要找的。p>
EDIT2(代码示例):
public static void positionMap(GoogleMap map, LatLng start, LatLng end) {
// zoom the map so both locations are visible
LatLngBounds bounds = LatLngBounds.builder().include(start).include(end).build();
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 200));
// find the bearing
float[] results = new float[3];
Location.distanceBetween(
start.latitude,
start.longitude,
end.latitude,
end.longitude,
results);
float bearing = results[2];
// position the map so the two markers are vertically aligned
CameraPosition position = map.getCameraPosition();
CameraPosition cameraPosition = new CameraPosition.Builder(position)
.target(Utils.median(start, end))
.bearing(bearing)
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
【问题讨论】:
标签: android google-maps bearing