Google Map API V2 - How do I keep a marker in the center of the screen while user is scrolling the map ?
My purpose is to let user choose a location. I use the follo
Get a marker reference when call addMarker. After when the camera moves, moves the marker to the target position returned by the camera.
private Marker marker;
public void onMapReady(final GoogleMap googleMap) {
LatLng sydney = new LatLng(-34, 151);
MarkerOptions markerOptions = new MarkerOptions().position(sydney).title("Marker in Sydney");
marker = googleMap.addMarker(markerOptions);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
googleMap.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {
@Override
public void onCameraMove() {
final LatLng target = googleMap.getCameraPosition().target;
marker.setPosition(target);
}
});
}