0

我使用 Overlays 在地图(版本 1)上嵌入了 PNG 图像:

    ....
    Bitmap map_scaled = Bitmap.createScaledBitmap(map_png, map_png.getWidth(), map_png.getHeight(), true);

....

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, false);
        if(shadow) return;
        Projection projection = mapView.getProjection();

        Point leftTop = new Point();
        Point rightTop = new Point();
        Point rightBottom = new Point();
        Point leftBottom = new Point();

        projection.toPixels(topGeoPoint, leftTop);
        projection.toPixels(new GeoPoint(topGeoPoint.getLatitudeE6(), bottomGeoPoint.getLongitudeE6()), rightTop);
        projection.toPixels(bottomGeoPoint, rightBottom);
        projection.toPixels(new GeoPoint(bottomGeoPoint.getLatitudeE6(), topGeoPoint.getLongitudeE6()), leftBottom);

        if (
                (leftTop.x < 0 || leftTop.y < 0) && 
                (rightTop.x < 0 || rightTop.y < 0) && 
                (rightBottom.x < 0 || rightBottom.y < 0) && 
                (leftBottom.x < 0 || leftBottom.y < 0)) {
            // Not on screen? Don't draw the overlay
            return;
        }

        //      GeoPoint mapCenter = mapView.getMapCenter();
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setAntiAlias(true);

        canvas.drawBitmap(original, null, new Rect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y), paint);


}

我想将代码迁移到版本 2。您有什么建议吗?在 Google Map v2 中是否有任何类似的组件可以做到这一点?

此致


截图。在此处输入图像描述

4

1 回答 1

0

也许我错过了理解,但如果你想在地图上添加标记,你可以这样做:

 private MarkerOptions createMapMarker(LocationWO mLocation) {

    MarkerOptions mMarker = new MarkerOptions()
            .position(
                    new LatLng(mLocation.getmLatitude(), mLocation
                            .getmLongitude()))
            .title(mLocation.getmName())
            .snippet(mLocation.getmName())
            .icon(BitmapDescriptorFactory
                    .fromResource(R.drawable.map_pin_debug));
    return mMarker;
}

检查官方doku https://developers.google.com/maps/documentation/android/marker如果我没有正确理解您的问题,还有在地图上绘制形状的示例:https ://developers.google .com/maps/documentation/android/shapes

于 2013-05-06T20:06:35.457 回答