I want to draw a circle on map view. I want the user to input the radius and for that radius I have to show circle on map. After that I have to display markers on some locations on that circle.
I know how to display markers on on map view.
How can I draw circle on map view and to show markers on that circle boundary.
This isn't perfect, but here's a little code I put together to put a circle on a map. You could easily expand on it to set the colour of the circle etc. Most of the other code samples I've seen haven't taken into account scaling the circle size with the zoom level which is a common requirement when creating circles. Circle Radius is in meters.
In the implementation of the
ItemizedOverlay
, do something like the methoddrawCircle
from theonDraw
methodJust to bring this up to date... they've made it very easy to do on Google Maps API v2.
Where radius is in meters.
As for markers on the boundary, that should be relatively easy to do - just follow the 'Circles' Demo in the Google Maps sample code here: https://developers.google.com/maps/documentation/android/intro#sample_code
In case someone was looking for an answer using Google Maps API v2, here's a snippet of what I did. It's really more of a geographical approach.
}
The good thing about this is that you don't have to redraw anything after zooming or panning the map - the circle gets resized and moved accordingly. The downside is that this doesn't work if you want a circle on either north or south pole - it'll all go bezerk, but, hopefully, that's not the case 99% of the time :)
If you put the following code in your overlay's draw method, it will draw a circle radius 20 px in the centre of your mapView
You should be able to adapt it to suit your needs
For Kotlin, to draw circle in center of the map, you can use
mMap
isGoogleMap