java– 在Google Map v2上绘制五个透明的外接圆

java– 在Google Map v2上绘制五个透明的外接圆,第1张

概述我最近开始使用谷歌地图v2,并发现很多事情已经改变.以前我使用的是GoogleMapv1,所以我使用的是MapView的概念.我正在尝试创建五个透明的外接圆,中心作为我当前的位置.下面是代码,我用于谷歌地图v1绘制圆圈,它对我来说很好.现在我想在GoogleMapv2上绘制我在下面的代码中绘制的

我最近开始使用谷歌地图v2,并发现很多事情已经改变.以前我使用的是Google Map v1,所以我使用的是MapVIEw的概念.

我正在尝试创建五个透明的外接圆,中心作为我当前的位置.下面是代码,我用于谷歌地图v1绘制圆圈,它对我来说很好.现在我想在Google Map v2上绘制我在下面的代码中绘制的相同圆圈.我不能在这里使用MapVIEw,因为我在这里使用GoogleMap对象.任何人都可以帮我这个在Google Map v2上绘制圆圈,中心是我当前的位置

@OverrIDepublic 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对象,以便我可以在谷歌地图v2上绘制圆圈?

谢谢您的帮助.

更新的代码: –

我需要在Google Maps v2上绘制五个圆圈,将当前位置作为圆心.意味着五个圆中的每一个具有相同的中心但具有不同的半径:第一个圆的半径为10米,第二个圆半径为20米,第三个圆半径为30米,第四个圆半径为40米,第五个圆半径为50米.我正在使用Google Maps v2.

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

我正在尝试这样的东西在谷歌地图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中创建此圈子时遇到问题.任何帮助将不胜感激.

解决方法:

只需使用GoogleMap.addCircle(…)为地图添加一个圆圈

见documentation

更新:

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

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

@OverrIDepublic 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;}
总结

以上是内存溢出为你收集整理的java – 在Google Map v2上绘制五个透明的外接圆全部内容,希望文章能够帮你解决java – 在Google Map v2上绘制五个透明的外接圆所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1096100.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存