【问题标题】:Android - Create google map projections V2Android - 创建谷歌地图投影 V2
【发布时间】:2013-05-06 18:00:08
【问题描述】:

我使用 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 中是否有类似的组件?

最好的问候


截图。

【问题讨论】:

  • 嗨,Macie,我上传了截图。如您所见,我想在地图上放置一张 PNG 图像,但由左上角(纬度-经度)和右下角(纬度-经度)固定。如果我放大或缩小地图,PNG 图像应该调整大小
  • 使用 API v2 中的 GroundOverlay 非常简单。
  • 伟大的 Macie,这就是解决方案,而且非常简单

标签: android google-maps-android-api-2 map-projections


【解决方案1】:

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

 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

【讨论】:

    猜你喜欢
    • 2012-11-29
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多