Skip to content Skip to sidebar Skip to footer

Android Google Map Location Item Click With Starting New Activity

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { public void onInfoWindowClick(Marker marker)

Solution 1:

InfoWindow isn't a live view so this what i have do :

public class CustomInfoWindowAdpater implements GoogleMap.InfoWindowAdapter,Picasso.Listener {
        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {

        }

        private final View view;

        public CustomInfoWindowAdpater() {
            view = getLayoutInflater()
                    .inflate(R.layout.custominfowindow, null);
        }

        public View getInfoWindow(final Marker marker) {
            MainApplication.currentlyClickedMarker = marker;
            final LinearLayout linearLayout = (LinearLayout)view.findViewById(R.id.ll_custominfowindow);
            linearLayout.setTag(marker.getId());


            GoogleMapFragment.this.marker = marker;

            String url = null;

            if (marker.getId() != null && markers != null && markers.size() > 0) {
                if ( markers.get(marker.getId()) != null &&
                        markers.get(marker.getId()) != null) {
                    url = markers.get(marker.getId());
                }
            }

           final ImageView image = ((ImageView) view.findViewById(R.id.badge));


            //Get the Image from web using Picasso and update the info contents
            if (url != null && !url.equalsIgnoreCase("null")
                    && !url.equalsIgnoreCase("")) {
                Picasso.with(GoogleMapFragment.this).load(Uri.parse(url)).resize(50,50)
                        .into(image, new Callback() {
                            @Override
                            public void onSuccess() {
                                getInfoContents(marker);
                            }

                            @Override
                            public void onError() {

                            }
                        });
            }
            else{
                image.setImageResource(R.drawable.ic_launcher);
            }

            final String title = marker.getTitle();
            final TextView titleUi = ((TextView) view.findViewById(R.id.title));
            if (title != null) {
                titleUi.setText(title);
            } else {
                titleUi.setText("");
            }

            final String snippet = marker.getSnippet();
            final TextView snippetUi = ((TextView) view
                    .findViewById(R.id.snippet));
            if (snippet != null) {
                snippetUi.setText("");
            } else {
                snippetUi.setText("");
            }

            return view;
        }

...

@Override
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);
     googleMap.setInfoWindowAdapter(new CustomInfoWindowAdpater());
}

...

@Override
    public void onInfoWindowClick(Marker marker) {
        // open the application
        Intent intent = new Intent(GoogleMapFragment.this,SplashScreenAppPro.class);
        // SplashScreen
        intent.putExtra("id",marker.getSnippet());
        intent.putExtra("nom_profil",  marker.getTitle());
        startActivity(intent);


    }

*Your Activity/Fragment must implement GoogleMap.OnInfoWindowClickListener


Post a Comment for "Android Google Map Location Item Click With Starting New Activity"