绘制5透明外接圆上的谷歌地图V2 [英] Draw five transparent circumcircles on the Google Map v2

查看:306
本文介绍了绘制5透明外接圆上的谷歌地图V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近已经开始与谷歌地图V2工作,想通了很多事情已经改变。 previously我用谷歌地图V1,所以我是用图形页面的概念。

I have recently started working with Google Map v2 and figured it out lot of things have been changed. Previously I was using Google Map v1 so I was using the concept of MapView.

我想创建五类透明外接圆中心为我现在的位置。下面是code,我使用了谷歌地图V1 绘制圆,这是工作对我罚款。现在,我想画,我画我的跌破code。在谷歌地图V2 同一个圆。因为我使用的GoogleMap的位置反对我不能使用图形页面在这里。任何人都可以帮我这个与中心借鉴了谷歌地图V2圆我的当前位置

I am trying to create five transparent circumcircles with the center as my current location. Below is the code, I was using for Google Map v1 to draw the circle and it was working fine for me. Now I am trying to draw the same circle that I have drawn in my below code on the Google Map v2. I cannot use MapView here as I am using GoogleMap object here. Can anyone help me with this to draw the circle on the Google Map v2 with center as my current location

@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();
        }
}

延伸覆盖,并画上了谷歌地图的圆圈V1

A simple class that extends Overlay and draw the circle on the 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;
    }
}

我只需要画,我画中的谷歌地图V2我上面code中的同一个圆。有什么办法,我可以用上面的code与GoogleMap的对象,这样我就可以在谷歌地图V2画圈圈?

I just need to draw the same circle that I have drawn in my above code on the Google Map v2. Is there any way, I can use the above code with GoogleMap object so that I can draw circles on the Google Map v2?

感谢您的帮助。

更新code: -

我需要考虑当前位置为圆心画上的谷歌地图V2 5圆圈圈。这意味着每个五界的具有相同的中心,但具有不同半径:所述第一圆将具有半径10米,20米第二圆半径,为30m第三圆半径,40米第四圆半径,以及50μm的第五圆半径。我使用谷歌地图V2。

I need to draw five circle-circle on the Google Maps v2 by taking the current location as the center of a circle. Meaning that each of the five circles have the same center but with different radii: the first circle will have radius of 10m, second circle radius of 20m, third circle radius of 30m, fourth circle radius of 40m, and fifth circle radius of 50m. I am using Google Maps v2.

和我需要表现出的圆心标记为好。

And I need to show a marker on the center of the circle as well.

我想这样的事情画上的谷歌地图V2圈,但它绘制只有一个圈子,而不是五circum圈

I am trying something like this to draw the circle on the Google Map v2 but it draws only one circle and not the five circum-circle

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);

我需要精确地绘制circum圈这样的 -

I need to draw circum-circle exactly like this-

任何人可以帮助我呢?我在做这个圈子里的谷歌地图V2有问题。任何帮助将AP preciated。

Can anybody help me with this? I am having problem in making this circle in Google Map v2. Any help will be appreciated.

推荐答案

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

Just add a circle to the map using googleMap.addCircle(...)

文档

更新:

我没有完全按照我说的做,我有没有问题,做你想做什么

I did exactly as I said to do and I had no problem doing what you want

这里是code,超简单超基本....

here is the code, super simple super basic....

@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;
}

这篇关于绘制5透明外接圆上的谷歌地图V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆