我正在为我的Android应用程序使用新的API(Google Map API V2),我已经创建了地图并向其添加了标记,现在我的任务是手动在任何标记周围创建圆圈,并且我希望为用户提供一个功能,使他可以相应地增加该圆的半径。为此,我提供了一条滑动条,当用户增加该条时,圆的半径将增加,反之亦然。
如果有人知道如何使用Google Map API V2实现此操作,请帮忙,
谢谢
如果有人知道如何使用Google Map API V2实现此操作,请帮忙,
谢谢
我也一直在处理这个问题,最终找到了以下解决方案。尽管不完美,但我必须使用非常大的画布才能避免圆形边缘变得模糊。
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));
}
-- 编辑 -- Google 更新了 API。现在您可以轻松地向地图添加一个圆: https://developers.google.com/maps/documentation/android/shapes?hl=nl#circles
这个更好:
double radiusInMeters = 100.0;
//red outline
int strokeColor = 0xffff0000;
//opaque red fill
int shadeColor = 0x44ff0000;
CircleOptions circleOptions = new CircleOptions().center(position).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(2);
mCircle = map.addCircle(circleOptions);
MarkerOptions markerOptions = new MarkerOptions().position(position);
mMarker = map.addMarker(markerOptions);
GoogleMap map;
// ... get a map.
// Add a circle in Sydney
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(-33.87365, 151.20689))
.radius(10000)
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
private GoogleMap mMap;
/*Create circle objects*/
Circle currentCircle;
/**
* create circle when user want to set region
* @param currentMarker this is user selected marker
* @param radius pass radius value to circle object
*/
private void createCircle(Marker currentMarker ,Double radius){
//check circle is exist or not
//if exist remove
if(currentCircle!=null){
currentCircle.remove();
}
currentCircle=mMap.addCircle(new CircleOptions().center(currentMarker.getPosition()).radius(radius)
.strokeColor(Color.parseColor("#FF007A93"))
.fillColor(Color.parseColor("#40007A93"))
.strokeWidth(2));
float zoomLevel = getZoomLevel(radius);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentMarker.getPosition(), zoomLevel));
}