2012-07-25 176 views
0

所以,我有我写了填补根据各地地理点获取自定义覆盖

阵列的透明的蓝色覆盖的定制覆盖项目的中心点
@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); 
} 

我需要的是一种方法,得到这个覆盖的中心点,所以我可以放置一个标记, 任何人有任何想法?

回答

1

虽然我不熟悉android框架,但我假设你在java中编写和使用某种google maps api。但我很熟悉图形和地理信息系统的开发。我建议您首先检查标准api是否有某种返回给您的RectangularBounds对象或类似的某种 getBounds(路径)。然后从矩形边界,你可以要求bounds.getCenter(),它返回边界的中心作为地理点或其他度量。如果你使用的像素只是像你这样转换地址点...

如果getBounds在api中不存在(很难相信),只需实现一个简单的接口,就可以在网上找到很多示例。查找地理形状为地理点的范围,如果你需要的像素用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))) 
} 

希望这将有助于

+0

你是对的,我俯瞰方法已经在centerX和centerY的API中了,谢谢 – eoghanm 2012-07-25 15:42:04