Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MyLocation-Button at Google Map API V2

I want to make that when click in MyLocation-Button show a Toast. I try this code:

public void setMyLocationLayerEnabled(View v) {
    Toast toast = Toast.makeText(getApplicationContext(), "Example de Message for Android", Toast.LENGTH_SHORT);
    toast.show();
}

But no work. I hope somebody of you can help me!

like image 706
Cabezas Avatar asked Dec 04 '22 07:12

Cabezas


2 Answers

map.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() {
                @Override
                public boolean onMyLocationButtonClick() {
                    Toast.makeText(
                            getActivity(),
                            "Example de Message for Android",
                            Toast.LENGTH_SHORT).show();
                    return true;
                }
            });
like image 191
Cabezas Avatar answered Dec 10 '22 12:12

Cabezas


To get the current location after clicking MyLocationButton, then use

`googleMap.getMyLocation();  //Deprecated,  So use `googleMap.setMyLocationEnabled(true); //Which allows to deal with current location`

inside setOnMyLocationButtonClickListener.

Reference link: https://www.androidtutorialpoint.com/intermediate/android-map-app-showing-current-location-android/

Hope it helps ! And thanks to Cabezas.

like image 25
Sakthimuthiah Avatar answered Dec 10 '22 11:12

Sakthimuthiah