Multiple line or break line in .snippet (google maps apiv2)

后端 未结 3 1861
Happy的楠姐
Happy的楠姐 2020-12-05 20:45

I\'m developing in google maps APIv2. The issue that I\'m facing now is I only able to add in one line of word in info windows/snippet. But the output that I want is able to

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 21:11

    You need to use a custom InfoWindowAdapter to change the layout of InfoWindow to a custom design defined using a layout file. Basically you need to :

    1. Declare your function using GoogleMap.setInfoWindowAdapter(Yourcustominfowindowadpater)
    2. Have a class like below:

    ...

    class Yourcustominfowindowadpater implements InfoWindowAdapter {
        private final View mymarkerview;
    
        Yourcustominfowindowadpater() {
            mymarkerview = getLayoutInflater()
                .inflate(R.layout.custominfowindow, null); 
        }
    
        public View getInfoWindow(Marker marker) {      
            render(marker, mymarkerview);
            return mymarkerview;
        }
    
        public View getInfoContents(Marker marker) {
           return null;
        }
    
        private void render(Marker marker, View view) {
           // Add the code to set the required values 
           // for each element in your custominfowindow layout file
        }
    }
    

提交回复
热议问题