Setting max zoom level in google maps android api v2

后端 未结 16 2276
无人共我
无人共我 2020-12-02 17:14

I\'m currently working on developing apps by using Google maps android API v2. My code is as follows. Suppose map has several markers and zoom up to show all markers in disp

16条回答
  •  孤城傲影
    2020-12-02 17:29

    What I ended up doing is creating my own buttons and disabling the default ones so I would have full control.

    Something like this in the layout to place the buttons:

    
    
        

    Then this in the code to disable the default buttons and setup our new ones:

    map.getUiSettings().setZoomControlsEnabled(false);
    
    // setup zoom control buttons
    Button zoomout = (Button) findViewById(R.id.bzoomout);
    zoomout.setOnClickListener(new OnClickListener(){
    
        @Override
        public void onClick(View v) {
            if(map.getCameraPosition().zoom >= 8.0f){
                // Zoom like normal
                map.animateCamera(CameraUpdateFactory.zoomOut());
            }else{
                // Do whatever you want if user went too far
                Messages.toast_short(MapsActivity.this, "Maximum zoom out level reached");
            }
        }
    
    });
    
    Button zoomin = (Button) findViewById(R.id.bzoomin);
    zoomin.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
            if (map.getCameraPosition().zoom <= 14.0f) {
                // Zoom like normal
                map.animateCamera(CameraUpdateFactory.zoomIn());
            } else {
                // Do whatever you want if user went too far
                Messages.toast_short(MapsActivity.this, "Maximum zoom in level reached");
            }
        }
    });
    

提交回复
热议问题