Android: Drag map while keeping marker at the center

后端 未结 2 440
别跟我提以往
别跟我提以往 2020-12-09 06:00

I am currently getting Current Location of device (lat,lng) in MapActivity. Now , I want to let the user move the map, while keeping the marker at the center. This means tha

2条回答
  •  情书的邮戳
    2020-12-09 06:25

    Having a map under an ImageView with your marker icon would be the best way to go here (just a framelayout with your map fragment under and your marker image centered on top should work). Then you can use an OnCameraIdleListener which would receive a callback when the map movement has ended. So just set an instance of OnCameraIdleListener to your map to listen for movement callbacks like so:

    map.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
            @Override
            public void onCameraIdle() {
                //get latlng at the center by calling
                LatLng midLatLng = map.getCameraPosition().target;
            }
        });
    

提交回复
热议问题