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

后端 未结 7 1793
执念已碎
执念已碎 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:32

    This is the solution

        private GoogleMap mMap;
        private Marker markerCenter;
    
        @Override
        public void onMapReady(GoogleMap googleMap) {
    
           mMap = googleMap; 
    
           MarkerOptions markerOptions = new MarkerOptions();
           markerOptions.position(mMap.getCameraPosition().target);
           markerCenter = mMap.addMarker(markerOptions);
    
           mMap.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {
              public void onCameraMove() {
                  markerCenter.setPosition(mMap.getCameraPosition().target);
              }
           });
    
        }
    

提交回复
热议问题