V2到周围画一个圆针

V2到周围画一个圆针

本文介绍了如何使用谷歌地图API V2到周围画一个圆针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用新的API(谷歌地图API V2)为我的Andr​​oid应用程序,我已经完成创建地图和添加标记吧,现在我的任务是手动创建一个圆圈周围的任何标记的同时,我想提供一个功能,他可以增加圆的半径。因此,为了这个,我都给予了吧,当用户增加了禁止圆的半径将增加,反之亦然用户。

I am using the new API(Google Map API V2) for my android application, i have done creating the map and adding markers to it, now my task is to manually create a circle around any of the marker and also i want to provide a functionality to the user that he can increase the radius of that circle accordingly, for this i have given a bar, when user increases that bar the radius of circle will increase and vice versa.

如果有人知道如何使用谷歌地图API V2,请您帮助做到这一点,

If anybody knows how to do this using Google Map API V2 then please help,

感谢

推荐答案

我一直在这一点,我发现了以下解决方案。这还不够完美,因为我不得不做出一个非常大的画布,以prevent变得模糊圈的边缘。

I have been working on this too and I found the following solution. It's still not perfect, because I had to make a very large Canvas to prevent the edge of the circle from becoming blurry.

private void addCircleToMap() {

    // circle settings
    int radiusM = // your radius in meters
    double latitude = // your center latitude
    double longitude = // your center longitude
    LatLng latLng = new LatLng(latitude,longitude);

    // draw circle
    int d = 500; // diameter
    Bitmap bm = Bitmap.createBitmap(d, d, Config.ARGB_8888);
    Canvas c = new Canvas(bm);
    Paint p = new Paint();
    p.setColor(getResources().getColor(R.color.green));
    c.drawCircle(d/2, d/2, d/2, p);

    // generate BitmapDescriptor from circle Bitmap
    BitmapDescriptor bmD = BitmapDescriptorFactory.fromBitmap(bm);

// mapView is the GoogleMap
    mapView.addGroundOverlay(new GroundOverlayOptions().
            image(bmD).
            position(latLng,radiusM*2,radiusM*2).
            transparency(0.4f));
}

- 编辑 -谷歌更新了API。现在,您可以了一圈轻松地添加到您的地图:<一href="https://developers.google.com/maps/documentation/android/shapes?hl=nl#circles">https://developers.google.com/maps/documentation/android/shapes?hl=nl#circles

-- EDIT --Google updated the API. You can now easily add a circle to your map:https://developers.google.com/maps/documentation/android/shapes?hl=nl#circles

这篇关于如何使用谷歌地图API V2到周围画一个圆针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:38