Reputation: 3587
I need to draw circle of some radius on some given location that can be dragged to some other point on map I can well draw circle like this
mMap.addCircle(new CircleOptions().center(circleLocation).radius(10).strokeColor(Color.RED).fillColor(Color.RED));
Now I need to drag this circle on map in such a way that when I click on this circle map gets locked and on moving my finger this circle should move on circle and not map itself
Thanks in advance!!!
Upvotes: 3
Views: 2142
Reputation: 22232
View
above the SupportMapFragment
OnTouchListener
to this View
Projection
to convert x,y to LatLng
and Location.distanceBeetween
false
to give map chance to handle eventtrue
and save relevant variablesProjection
to calculate new center based on initial and new x,yUpvotes: 1
Reputation: 5440
Here is the code to draw circle above map,
CircleOptions circleOptions = new CircleOptions()
.center(new LatLng(37.4, -122.1))
.radius(1000)); // In meters
// Get back the mutable Circle
Circle circle = myMap.addCircle(circleOptions);
And GoogleMap doesn't have a touch listener, so you'll have to override onTouchEvent for the parent view of your MapFragment to drag your circle around.
Upvotes: -1
Reputation: 3542
I don't know how to do with shapes but one alternative is to use a marker. It doesn't have the exact result as the marker is drawn flush to the screen view rather than flush to the map but it does have built in drag support. You would need to create a circle image.
map.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.draggable(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.circle)));
Upvotes: 1