I have tried many of the solutions that abound here in the forum of the operation of onmarkerclick () but none have worked.
I am working with an app that uses the google maps api and we want to program a route tracer.
The operation that I am trying to achieve now is that by clicking on a marker you can trace the path to it, the problem is that the onmarkerclick method is not working or returning anything.
I will add the 2 parts of the code that I consider important to be able to find the solution to the problem:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setOnMapClickListener(this);
mMap.setOnMarkerClickListener(this);
mMap.setOnInfoWindowClickListener(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
else {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
// Add layer
try {
layer = new KmlLayer(mMap, R.raw.kmltest, getApplicationContext());
layer.addLayerToMap();
// Set a listener for geometry clicked events.
layer.setOnFeatureClickListener(new KmlLayer.OnFeatureClickListener() {
@Override
public void onFeatureClick(Feature feature) {
Log.i("KML", "Feature clicked: " + feature.getProperty("CUA_DESCRI"));
}
});
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// end of layer add
}
public boolean onMarkerClick(Marker marker) {
Log.d("Comprobar markerclick", "onMarkerClick !!!!!!!!!!!!!!!!!! ");
btnTrazarRuta.hide();
//El destino que buscaremos al dar click
destinoRutaUnica = marker.getPosition().latitude + "," + marker.getPosition().longitude;
return false;
}
The onmarkerclick method should hide a button and get the position of the marker, but before that I put a logd to be able to see if it was at least entering the method, but no. It shows absolutely nothing.