Android Google Map - Clicked marker opens new activity or bigger window

前端 未结 5 1631
梦毁少年i
梦毁少年i 2020-12-14 02:41

I\'ve been searching for help on implementing OnMarkerClickListener but nothing I\'ve found has worked. This is my marker below and when clicked it only changes colour(light

5条回答
  •  爱一瞬间的悲伤
    2020-12-14 02:59

    This code handles the maker click event and loads a new layout (XML) with some information:

    /**
     * adding individual markers, displaying text on on marker click on a
     * bubble, action of on marker bubble click
     */
    private final void addLocationsToMap() {
        int i = 0;
        for (Stores store : storeList) {
            LatLng l = new LatLng(store.getLatitude(), store.getLongtitude());
    
            MarkerOptions marker = new MarkerOptions()
                    .position(l)
                    .title(store.getStoreName())
                    .snippet("" + i)
                    .icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
            googleMap.addMarker(marker);
            ++i;
        }
    
        googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
    
            @Override
            public void onInfoWindowClick(Marker marker) {
    
                try {
                    popUpWindow.setVisibility(View.VISIBLE);
                    Stores store = storeList.get(Integer.parseInt(marker
                            .getSnippet()));
    
                    // set details
                    email.setText(store.getEmail());
                    phoneNo.setText(store.getPhone());
                    address.setText(store.getAddress());
    
                    // setting test value to phone number
                    tempString = store.getPhone();
                    SpannableString spanString = new SpannableString(tempString);
                    spanString.setSpan(new UnderlineSpan(), 0,
                            spanString.length(), 0);
                    phoneNo.setText(spanString);
    
                    // setting test value to email
                    tempStringemail = store.getEmail();
    
                    SpannableString spanString1 = new SpannableString(tempStringemail);
                    spanString1.setSpan(new UnderlineSpan(), 0, spanString1.length(), 0);
                    email.setText(spanString1);
    
                    storeLat = store.getLatitude();
                    storelng = store.getLongtitude();
    
                } catch (ArrayIndexOutOfBoundsException e) {
                    Log.e("ArrayIndexOutOfBoundsException", " Occured");
                }
    
            }
        });
    
    }
    

提交回复
热议问题