2012-07-25 117 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