MobApp/app/src/main/java/com/example/monagendapartage/Fragments/MyEventsFragments/DisplayUsersFragment.java
/**
     * Fonction permettant d'affiche les utilisateurs sur une carte Google Map
     */
Fonction permettant d'affiche les utilisateurs sur une carte Google Map
Fonction permettant d ' affiche les utilisateurs sur une carte Google Map
private void _placeMarkersOnMap() {
        Activity activity = getActivity();
        if (isAdded() && activity != null) {
            if (mUsers.size() > 0) {
                SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
                mapFragment.getMapAsync(new OnMapReadyCallback() {
                    @Override
                    public void onMapReady(GoogleMap mMap) {
                        mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                        mMap.clear(); 
                        CameraPosition googlePlex = CameraPosition.builder()
                                .target(new LatLng(47.155404566149336,2.6491201250000813))
                                .zoom(2)
                                .bearing(0)
                                .tilt(45)
                                .build();
                        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(googlePlex), 10000, null);
                        for(UserModel usr: mUsers) {
                            String adress = usr.getNumeroVoie() + " " + usr.getTypeVoie() + " " + usr.getNomVoie() + ","  + usr.getCodePostal();
                            LatLng adressLatLng = getLocationFromAddress(getActivity(), adress);
                            if (adressLatLng != null) {
                                mMap.addMarker(new MarkerOptions()
                                        .position(new LatLng(adressLatLng.latitude, adressLatLng.longitude))
                                        .title(usr.getId())
                                        .icon(bitmapDescriptorFromVector(getActivity(),R.drawable.ic_person_black_24dp)));
                            }
                        }
                        _showProgress(false);
                        mSwipeRefreshLayout.setRefreshing(false);
                        noResultsLayout.setRefreshing(false);
                        noResultsLayout.setVisibility(View.GONE);
                        aroundMe.setText("Carte");
                        mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                            @Override
                            public boolean onMarkerClick(Marker marker) {
                                Intent intent = new Intent(getActivity(), UserProfilViewActivity.class);
                                intent.putExtra("idUser", marker.getTitle());
                                startActivity(intent);
                                return true;
                            }
                        });
                    }
                });
            } else {
                Log.d("noResult", "ok ! ::::::");
                mProgressView.setVisibility(View.GONE);
                mSwipeRefreshLayout.setVisibility(View.GONE);
                noResultsLayout.setVisibility(View.VISIBLE);
                noResultsLayout.setRefreshing(false);
            }
        }
    }
private void _placeMarkersOnMap ( ) { Activity activity = getActivity ( ) ; if ( isAdded ( ) && activity != null ) { if ( mUsers . size ( ) > 0 ) { SupportMapFragment mapFragment = ( SupportMapFragment ) getChildFragmentManager ( ) . findFragmentById ( R . id . map ) ; mapFragment . getMapAsync ( new OnMapReadyCallback ( ) { @ Override public void onMapReady ( GoogleMap mMap ) { mMap . setMapType ( GoogleMap . MAP_TYPE_NORMAL ) ; mMap . clear ( ) ; CameraPosition googlePlex = CameraPosition . builder ( ) . target ( new LatLng ( 47.155404566149336 , 2.6491201250000813 ) ) . zoom ( 2 ) . bearing ( 0 ) . tilt ( 45 ) . build ( ) ; mMap . animateCamera ( CameraUpdateFactory . newCameraPosition ( googlePlex ) , 10000 , null ) ; for ( UserModel usr : mUsers ) { String adress = usr . getNumeroVoie ( ) + " " + usr . getTypeVoie ( ) + " " + usr . getNomVoie ( ) + "," + usr . getCodePostal ( ) ; LatLng adressLatLng = getLocationFromAddress ( getActivity ( ) , adress ) ; if ( adressLatLng != null ) { mMap . addMarker ( new MarkerOptions ( ) . position ( new LatLng ( adressLatLng . latitude , adressLatLng . longitude ) ) . title ( usr . getId ( ) ) . icon ( bitmapDescriptorFromVector ( getActivity ( ) , R . drawable . ic_person_black_24dp ) ) ) ; } } _showProgress ( false ) ; mSwipeRefreshLayout . setRefreshing ( false ) ; noResultsLayout . setRefreshing ( false ) ; noResultsLayout . setVisibility ( View . GONE ) ; aroundMe . setText ( "Carte" ) ; mMap . setOnMarkerClickListener ( new GoogleMap . OnMarkerClickListener ( ) { @ Override public boolean onMarkerClick ( Marker marker ) { Intent intent = new Intent ( getActivity ( ) , UserProfilViewActivity . class ) ; intent . putExtra ( "idUser" , marker . getTitle ( ) ) ; startActivity ( intent ) ; return true ; } } ) ; } } ) ; } else { Log . d ( "noResult" , "ok ! ::::::" ) ; mProgressView . setVisibility ( View . GONE ) ; mSwipeRefreshLayout . setVisibility ( View . GONE ) ; noResultsLayout . setVisibility ( View . VISIBLE ) ; noResultsLayout . setRefreshing ( false ) ; } } }
Fonction permettant d'affiche les utilisateurs sur une carte Google Map
Fonction permettant d ' affiche les utilisateurs sur une carte Google Map
//clear old markers // startRelativeLayout.setVisibility(View.VISIBLE);