如何在谷歌地图V2 Android上移动标记

时间:2014-04-08 13:17:27

标签: android google-maps google-maps-markers

这是我的代码:

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));}}

如何移动此标记" maposition" ?

2 个答案:

答案 0 :(得分:2)

map.addMarker(...)

返回对Marker对象的引用。那个对象有一个

setPosition(LatLng latlng)

方法。因此,使用它可以随时随地移动此标记。

答案 1 :(得分:-1)

 mMap.addMarker(new MarkerOptions()
            .title("title")
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))
            .position(new LatLng(latitude, longitude));