我正在尝试制作自定义InfoWindow,其中我有一个按钮和TextView,但该按钮不起作用,当我点击它时,单击整个infoWindow。 这是我的onReadyMap功能:
public void onMapReady(GoogleMap map) {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION}, 123);
}
else{
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
// Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if(location==null)
{
Toast.makeText(this,"erreur de connexion",Toast.LENGTH_SHORT);
}
if (location != null)
{ map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_window,null);
TextView nomCompagnie = (TextView) v.findViewById(R.id.txt_infoWindow_compagnie);
TextView assurance = (TextView) v.findViewById(R.id.txt_infoWindow_assurance);
TextView dispo = (TextView) v.findViewById(R.id.txt_infoWindow_dispo);
TextView loca = (TextView) v.findViewById(R.id.txt_infoWindow_localisation);
Button notifier = (Button) v.findViewById(R.id.btn_infowindow_notif);
nomCompagnie.setText(marker.getTitle());
LatLng latlng=marker.getPosition();
loca.setText("("+latlng.latitude+","+latlng.longitude+")");
return v;
}
});
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(getApplicationContext(),"clicked",Toast.LENGTH_SHORT).show();
return false;
}
});
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
map.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Je suis ici !")).showInfoWindow();
for(int i=0;i<arrayPosition.size();i++)
{
map.addMarker(new MarkerOptions().position(new LatLng(arrayPosition.get(i).getLatitude(), arrayPosition.get(i).getLongitude())).title("Je suis numéro "+i+"")).showInfoWindow();
// Log.d("wiwwww", "heereee");
}
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user
.zoom(12) // Sets the zoom
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
map.setMyLocationEnabled(true);
}}}