How to use MyLocation-Button in Google Map API V2

I want to do this when we click on MyLocation-Button to show Toast. I am trying 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 one of you can help me!

+4
source share
2 answers
map.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() {
                @Override
                public boolean onMyLocationButtonClick() {
                    Toast.makeText(
                            getActivity(),
                            "Example de Message for Android",
                            Toast.LENGTH_SHORT).show();
                    return true;
                }
            });
+11
source

To get the current location after clicking the MyLocationButton button, use

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

inside a set of OnMyLocationButtonClickListener.

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

Hope this helps! And thanks to Cabezas.

+3
source

Source: https://habr.com/ru/post/1525027/


All Articles