所以我有一个自定义的叠加项目,我已经写过它来填充基于一系列地理点的透明蓝色叠加层
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
Projection projection = mapView.getProjection();
Paint fill = new Paint();
fill.setColor(Color.BLUE);
fill.setAlpha(50);
fill.setStyle(Paint.Style.FILL_AND_STROKE);
Path path = new Path();
Point firstPoint = new Point();
projection.toPixels(geoPoints.get(0), firstPoint);
path.moveTo(firstPoint.x, firstPoint.y);
for (int i = 1; i < geoPoints.size(); ++i) {
Point nextPoint = new Point();
projection.toPixels(geoPoints.get(i), nextPoint);
path.lineTo(nextPoint.x, nextPoint.y);
}
path.lineTo(firstPoint.x, firstPoint.y);
path.setLastPoint(firstPoint.x, firstPoint.y);
canvas.drawPath(path, fill);
super.draw(canvas, mapView, shadow);
}
我需要的是获得此叠加层中心点的方法,以便我可以在其上放置标记, 有人有什么想法吗?
答案 0 :(得分:1)
虽然我不熟悉android框架,但我假设你用java编写并使用某种谷歌地图api。但我熟悉图形和地理开发。我建议你最先检查标准api是否有某种 getBounds(path)返回给你的RectangularBounds对象或类似的东西。然后,从矩形边界,您可以请求bounds.getCenter(),它将边界的中心返回为地理点或其他度量。如果您使用像素,只需转换像您所做的那样...
如果api中不存在getBounds(很难相信),只需实现一个简单的界面,就可以在网上找到很多例子。
用于查找地理点的地理形状边界的简单伪代码,如果需要像素分别使用x,y:
bounds = { topLeft: new GeoPoint(path[0]), bottomRight: new GeoPoint(path[0])};
for( point in path ){
bounds.topLeft.lat = max( bounds.topLeft.lat,point.lat );
bounds.topLeft.lng = min( bounds.topLeft.lng,point.lng );
bounds.bottomRight.lat = min( bounds.bottomRight.lat,point.lat );
bounds.bottomRight.lng = max( bounds.bottomRight.lng,point.lng );
}
bounds.getCenter(){
return new GeoPoint(rectangle center point);
// i am sure you will able to manage the code here )))
}
希望这会有所帮助