Google map for android my location custom button

前端 未结 4 1462
不知归路
不知归路 2020-12-01 00:53

How can I change google map my location default button? I set my location enable and map draw standard image to find location, is it possible to change default image?

4条回答
  •  被撕碎了的回忆
    2020-12-01 01:33

    See below xml file to custom button:

    
    
    
        
    
        
    
            
        
    
    
    

    Then in java class, declare your location button:

    private ImageView imgMyLocation;
            imgMyLocation = (ImageView) findViewById(R.id.imgMyLocation);
    

    Click Event:

    imgMyLocation.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    getMyLocation();
    
    }
    

    Get Location Method, in that just pass your current latitude and longitude.

    private void getMyLocation() {
            LatLng latLng = new LatLng(Double.parseDouble(getLatitude()), Double.parseDouble(getLongitude()));
            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 18);
            googleMap.animateCamera(cameraUpdate);
        }
        });
    

提交回复
热议问题