본문

180912(수) - Google Maps (Info Windows)

Google Maps


Info Windows

- tap on marker시, show되어지는 information이 목적인 window

- only one window will be displayed at a time

- another marker를 click하면, current info window closed and re-opens

- default bold title & (optional) snippet text


Add an info window

static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptions()
                         
.position(MELBOURNE)
                         
.title("Melbourne")
                         
.snippet("Population: 4,137,400"));


Show  / Hide an info window

static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptions()
                         
.position(MELBOURNE)
                         
.title("Melbourne"));
melbourne
.showInfoWindow();

- can also individual clustered markers (adding an info window for individual clustered markers.)


Custom info windows

InfoWindowAdapter

GoogleMap.setInfoWindowAdapter()

getInfoContents(Marker)가 null이면 default info window가 used


getInfoWindow()

entire info windows cutomized

getInfoContents()

default info window frame and background는 유지하면서 contents만 customizing


Note : info window는 live view가 아니며, rendered image (View.draw(Canvas)) 이다. 즉 viewing 이후에 changed is not reflected on the map.

   update가 필요하다면 showInfoWindow() 사용할 것.

   또한 not respect any interactivity typical for a normal view (touch or gesture event)


Info Window Comparison




Info window events

OnInfoWindowClickListener

GoogleMap.setOnInfoWindowClickListener(OnInfoWindowClickListener)


OnInfoWindowLongClickListener

GoogleMap.setOnInfoWindowCloseListener(OnInfoWindowCloseListener)


NoteonInfoWindowClose() event 는 already open info window를 tapping 했을 때, call되지만, Marker.showInfoWindow() programmatically call 했을 때는 not fire


view가 아닌 rendered image이므로 view의 여러 listener를 구분하기 어려워지기 때문에 custom info window에 button, checkboxes or text inputs같은 interactive components를 넣지 마라.

public class MarkerDemoActivity extends AppCompatActivity implements
       
OnInfoWindowClickListener,
       
OnMapReadyCallback {

   
private GoogleMap mMap;

   
@Override
   
public void onMapReady(GoogleMap map) {
        mMap
= map;
       
// Add markers to the map and do other map setup.
       
...
       
// Set a listener for info window events.
        mMap
.setOnInfoWindowClickListener(this);
   
}

   
@Override
   
public void onInfoWindowClick(Marker marker) {
       
Toast.makeText(this, "Info window clicked",
               
Toast.LENGTH_SHORT).show();
   
}
}


공유

댓글