2

我最近开始使用 Google Map v2 并发现很多事情都发生了变化。以前我使用的是 Google Map v1,所以我使用的是 MapView 的概念。

我正在尝试five transparent circumcircles使用center as my current location. 下面是代码,我用 forGoogle Map v1来画圆,对我来说效果很好。现在我正在尝试绘制与我在下面的代码中绘制的相同的圆圈Google Map v2。我不能在这里使用 MapView,因为我在这里使用 GoogleMap 对象。谁能帮我在 Google Map v2 上以中心为我当前位置绘制圆圈

@Override
public void onLocationChanged(Location location) {
        if (location != null) {
            GeoPoint point = new GeoPoint(
                    (int) (location.getLatitude() * 1E6),
                    (int) (location.getLongitude() * 1E6));

            // Create a LatLng object for the current location
            LatLng latLng = new LatLng(location.getLatitude(),  location.getLongitude());

            // Show the location on the Google Map
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

            // Zoom in the Google Map
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

        //   Below is the code for Google Map v1 to draw the circle on the map  

        //   if (mapOverlay == null) {
        //   mapOverlay = new MapOverlay(this, R.drawable.mark_blue);

        //   List<Overlay> listOfOverlays = mapView.getOverlays();
        //   listOfOverlays.add(mapOverlay);
        //   }

        //   mapOverlay.setPointToDraw(point);
        //   mapView.invalidate();
        }
}

扩展 Overlay 并在 Google Map v1 上绘制圆圈的简单类

class MapOverlay extends Overlay {
    private GeoPoint pointToDraw;
    int[] imageNames = new int[6];

    // This is the cached Point on the screen that will get refilled on
    // every draw
    private Point mScreenPoints;

    // This is the cached decoded bitmap that will be drawn each time
    private Bitmap mBitmap;

    // Cached Paint
    private Paint mCirclePaint;

    public MapOverlay(ProximityLocationListener gpsLocationListener,
            int currentUser) {
        imageNames[0] = currentUser;
        imageNames[1] = R.drawable.tenm;
        imageNames[2] = R.drawable.twentym;
        imageNames[3] = R.drawable.thirtym;
        imageNames[4] = R.drawable.fourtym;
        imageNames[5] = R.drawable.fiftym;

        // This only needs to be made here, once. It never needs to change.
        mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mCirclePaint.setColor(0x10000000);
        mCirclePaint.setStyle(Style.FILL_AND_STROKE);

        // We only need to load this image once and then just keep drawing
        // it when dirtyed.
        mBitmap = BitmapFactory.decodeResource(getResources(),
                imageNames[0]);

        // This Point object will be changed every call to toPixels(), but
        // the instance can be recycled
        mScreenPoints = new Point();
    }

    public void setPointToDraw(GeoPoint point) {
        pointToDraw = point;
    }

    public GeoPoint getPointToDraw() {
        return pointToDraw;
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {
        super.draw(canvas, mapView, shadow);
        mScreenPoints = mapView.getProjection().toPixels(pointToDraw,
                mScreenPoints);

        int totalCircle = 5;
        int radius = 40;
        int centerimagesize = 13;

        for (int i = 1; i <= totalCircle; i++) {
            canvas.drawCircle(mScreenPoints.x + 18, mScreenPoints.y + 36, i
                    * radius, mCirclePaint);
            canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),
                    imageNames[i]), ((mScreenPoints.x) + (i * radius)),
                    (mScreenPoints.y), null);
        }

        canvas.drawBitmap(mBitmap,
                (mScreenPoints.x - (centerimagesize / 2)),
                (mScreenPoints.y - (centerimagesize / 2)), null);
        super.draw(canvas, mapView, shadow);

        return true;
    }
}

我只需要在 Google Map v2 上绘制我在上面的代码中绘制的同一个圆圈。有什么办法,我可以将上面的代码与 GoogleMap 对象一起使用,以便我可以在 Google Map v2 上绘制圆圈?

谢谢您的帮助。

更新代码:-

我需要以当前位置为圆心,在 Google Maps v2 上绘制五个圆。这意味着五个圆中的每一个都具有相同的中心但具有不同的半径:第一个圆的半径为 10m,第二个圆的半径为 20m,第三个圆的半径为 30m,第四个圆的半径为 40m,第五个圆的半径为 50m。我正在使用谷歌地图 v2。

我还需要在圆的中心显示一个标记。

我正在尝试像这样在 Google Map v2 上绘制圆圈,但它只绘制一个圆圈而不是五个外接圆圈

CircleOptions circleOptions = new CircleOptions()
                  .center(latLng)   //set center
                  .radius(500)   //set radius in meters
                  .fillColor(Color.TRANSPARENT)  //default
                  .strokeColor(0x10000000)
                  .strokeWidth(5);

                  myCircle = googleMap.addCircle(circleOptions);

我需要像这样画外接圆-

在此处输入图像描述

有人可以帮我吗?我在 Google Map v2 中制作这个圆圈时遇到问题。任何帮助将不胜感激。

4

1 回答 1

4

只需使用在地图上添加一个圆圈googleMap.addCircle(...)

文档

更新:

我完全按照我说的去做了,我做你想做的事没有问题

在此处输入图像描述

这是代码,超级简单超级基本....

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    View view = super.onCreateView(inflater, container, savedInstanceState);
    GoogleMap map = getMap();

    int radius = 500;

    for(int i=0; i<5; i++){
        map.addCircle(new CircleOptions().center(new LatLng(0,0)).radius(radius).fillColor(0x30000000).strokeWidth(3));
        radius += 500;
    }
    return view;
}
于 2013-05-21T21:08:48.263 回答