본문
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
- 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 events
- GoogleMap.setOnInfoWindowClickListener(OnInfoWindowClickListener)
- OnInfoWindowLongClickListener
- GoogleMap.setOnInfoWindowCloseListener(OnInfoWindowCloseListener)
Note : onInfoWindowClose() 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();
}
}
'Mobile > Google Maps' 카테고리의 다른 글
180912(수) - Google Maps (Shapes) (0) | 2018.09.12 |
---|---|
180911(화) - Google Maps (Markers) (0) | 2018.09.11 |
180911(화) - Google Maps (Location data) (0) | 2018.09.11 |
180910(월) - Google Maps (Camera and View) (0) | 2018.09.10 |
180910(월) - Google Maps (Events) (0) | 2018.09.10 |
댓글