Im currently working with Google Maps API V2 on an android project, I need to be able to draw a circle around the users current position and display markers for points of interest within the radious around the users current position.
Im struggling to get the small marker that denotes the users current position so i can draw a circle around it.
This is my code so far.
//Set up map and display users current position.
MapFragment mapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.nearbyMapSearch);
mapFragment.getMapAsync(this);
final GoogleMap map = (((MapFragment) getFragmentManager().findFragmentById(R.id.nearbyMapSearch)).getMap());
map.setMyLocationEnabled(true);
//zoom to users location
GeoLocationHandler geoHandler = new GeoLocationHandler(getActivity().getApplicationContext());
Log.i("Search Fragment", "" + geoHandler.getCurrentLatitude() + " , " + geoHandler.getCurrentLongitude());
LatLng loc = new LatLng(geoHandler.getCurrentLatitude(), geoHandler.getCurrentLongitude());
//Begin animating camera.
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(loc.latitude, loc.longitude), 13));
//Instantiate new Camera position
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(loc.latitude, loc.longitude))
.zoom(3)
.bearing(0)
.tilt(0)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Any help with this would be much appreciated thanks.
Circle circle = map.addCircle(new CircleOptions()
.center(new LatLng(loc.latitude, loc.longitude))
.radius(1000)
.strokeColor(Color.RED)
.fillColor(Color.BLUE));
More info https://developers.google.com/android/reference/com/google/android/gms/maps/model/Circle
You should subscribe to updates of user location and reset the circle center with
circle.setCenter(newLocation);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With