How to change the position of a Marker on a Android Map v2

前端 未结 4 1127
-上瘾入骨i
-上瘾入骨i 2020-12-08 07:05

I need to do the following: I have a Marker on the map and I need to change the position of it. So I tried the following:

MarkerOptions a = new MarkerOptions         


        
4条回答
  •  执念已碎
    2020-12-08 07:59

    Define "marker" outside the function. for the first time, it will be null and "if" condition will be executed. for the second time "else" will be executed.

            Marker marker = null;    
            protected void onPostExecute(Coordinates coordinates) {
            LatLng latLong = new LatLng("lat", "long");
            if (marker == null) {
                MarkerOptions options = new MarkerOptions().position(latLong)
                        .title("Marker Title");
                marker = mMap.addMarker(options);
            }
            else {
                marker.setPosition(latLong);
            }
         mMap.moveCamera(CameraUpdateFactory.newLatLng(latLong));
         mMap.animateCamera(CameraUpdateFactory.zoomTo(16f));
        }
    

提交回复
热议问题