交互式infoWindow谷歌地图 - 安卓

时间:2016-12-09 19:00:23

标签: android google-maps google-maps-markers

我正在尝试制作自定义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);

    }}}

有没有人有任何想法只能使按钮可点击? enter image description here

1 个答案:

答案 0 :(得分:1)

我认为here正是您所寻找的。此外,您可以使用this库来执行您想要的操作。