我目前正在使用谷歌地图android API v2开发应用程序.我的代码如下.假设地图有几个标记并放大以显示所有标记.
LatLngBuilder.Builder builder = LatLngBounds.builder();
for(Marker m : markers){
builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10);
Run Code Online (Sandbox Code Playgroud)
此代码工作正常,但我想在缩放级别达到17.0f时停止动画; 看来map API没有这样的方法来控制缩放级别.有人知道解决这个问题的任何想法吗?
我需要绘制这样的东西,这些东西将被涂上并且几乎没有透明度
它也需要是可点击的(onTouch事件等)
我知道在API v1中你必须使用Overlay并使用canvas和一些数学来扩展它.在Google Map API v2中最简单的方法是什么?
PS:半径是可变的.
(供进一步参考)编辑1:
我实现了CanvasTileProvider子类并覆盖它的onDraw()方法:
@Override
void onDraw(Canvas canvas, TileProjection projection) {
// TODO Auto-generated method stub
LatLng tempLocation = moveByDistance(mSegmentLocation, mSegmentRadius, mSegmentAngle);
DoublePoint segmentLocationPoint = new DoublePoint(0, 0);
DoublePoint tempLocationPoint = new DoublePoint(0, 0);
projection.latLngToPoint(mSegmentLocation, segmentLocationPoint);
projection.latLngToPoint(tempLocationPoint, tempLocationPoint);
float radiusInPoints = FloatMath.sqrt((float) (Math.pow(
(segmentLocationPoint.x - tempLocationPoint.x), 2) + Math.pow(
(segmentLocationPoint.y - tempLocationPoint.y), 2)));
RectF segmentArea = new RectF();
segmentArea.set((float)segmentLocationPoint.x - radiusInPoints, (float)segmentLocationPoint.y - radiusInPoints,
(float)segmentLocationPoint.x + radiusInPoints, (float)segmentLocationPoint.y + radiusInPoints);
canvas.drawArc(segmentArea, getAdjustedAngle(mSegmentAngle),
getAdjustedAngle(mSegmentAngle + …
Run Code Online (Sandbox Code Playgroud) 我在地图上有两个标记,它们应该同时显示。
这是通过以下方式实现的:
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker markerTemp : markers) {
builder.include(markerTemp.getPosition());
}
Run Code Online (Sandbox Code Playgroud)
这工作正常。但是,当标记彼此靠近时,地图会非常缩小。事情是这样发生的:1- 我选择了两个彼此靠近的位置(缩放效果很好) 2- 我选择了两个彼此远离的位置(缩放效果很好) 3- 我选择了两个靠近的位置彼此(缩放保持不变,标记重叠)。
我检查了很多链接,包括:
(1) /sf/ask/2397314321/ (2) 谷歌地图的边界
(3)在 google maps android api v2 中设置最大缩放级别(4) Android map v2 zoom 以显示所有标记
(5)在 android 中调整谷歌地图 (api v2) 缩放级别 (6) 在 LatLngBounds 构建器上设置最大缩放级别