KingMaker KingMaker - 6 months ago 21
Android Question

How to move marker on google map V2 Android

This is my code:

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

map.setMyLocationEnabled(true);

LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);

Location myLocation = locationManager.getLastKnownLocation(provider);

map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();

final LatLng maposition = new LatLng(latitude, longitude);
map.moveCamera(CameraUpdateFactory.newLatLng(maposition));
map.animateCamera(CameraUpdateFactory.zoomTo(16));
map.addMarker(new MarkerOptions().title("MONKEY.D").snippet("Hace la fiesta").position(maposition).icon(BitmapDescriptorFactory));}}


How can I move this marker "maposition" ?

Answer Source
map.addMarker(...)

returns a reference to Marker object. And that objects has a

setPosition(LatLng latlng)

method. So use it to move this marker wherever you want.