Google Map API V2 - How do I keep a marker in the center of the screen while user is scrolling the map?

后端 未结 7 1787
执念已碎
执念已碎 2020-12-10 02:00

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

相关标签:
7条回答
  • 2020-12-10 02:52

    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);
                }
            });
    }
    
    0 讨论(0)
提交回复
热议问题