2
지도에 여러 마커를 추가하려고합니다. 각 마커는 고유 한 정보 창이 있습니다 (여러 줄에 정보를 표시하려면 infowindow가 필요합니다). 그것을하는 방법을 이해하십시오. Google 문서를 이미 읽었으므로 이제 샘플 코드 또는 자습서를 찾고 있습니다. 아무도 도와 줄 수 있습니까?Google지도 Api v2 - 자체 정보창이있는 다중 마커
지도에 여러 마커를 추가하려고합니다. 각 마커는 고유 한 정보 창이 있습니다 (여러 줄에 정보를 표시하려면 infowindow가 필요합니다). 그것을하는 방법을 이해하십시오. Google 문서를 이미 읽었으므로 이제 샘플 코드 또는 자습서를 찾고 있습니다. 아무도 도와 줄 수 있습니까?Google지도 Api v2 - 자체 정보창이있는 다중 마커
이 코드를 살펴보면 내 행동을 설명하는 설명이 있습니다. 하지만 미리 정의 된 XML 레이아웃의 InfoWindow
을 만들면 런타임에 채우기를 만들어야합니다.
// Setting a custom info window adapter for the google map
map.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker args) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker args) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);
// Getting the position from the marker
clickMarkerLatLng = args.getPosition();
TextView title = (TextView) v.findViewById(R.id.tvTitle);
title.setText(args.getTitle());
//Setting InfoWindow click listener
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker)
{
if (SGTasksListAppObj.getInstance().currentUserLocation!=null)
{
if (String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) &&
String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLongitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
{
Toast.makeText(getApplicationContext(), "This your current location, navigation is not needed.", Toast.LENGTH_SHORT).show();
}
else
{
FlurryAgent.onEvent("Start navigation window was clicked from daily map");
tasksRepository = SGTasksListAppObj.getInstance().tasksRepository.getTasksRepository();
for (Task tmptask : tasksRepository)
{
String tempTaskLat = String.valueOf(tmptask.getLatitude());
String tempTaskLng = String.valueOf(tmptask.getLongtitude());
Log.d(TAG, String.valueOf(tmptask.getLatitude())+","+String.valueOf(clickMarkerLatLng.latitude).substring(0, 8));
if (tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
{
task = tmptask;
break;
}
}
Intent intent = new Intent(getApplicationContext() ,RoadDirectionsActivity.class);
intent.putExtra(TasksListActivity.KEY_ID, task.getId());
startActivity(intent);
}
}
else
{
Toast.makeText(getApplicationContext(), "Your current location could not be found,\nNavigation is not possible.", Toast.LENGTH_SHORT).show();
}
}
});
// Returning the view containing InfoWindow contents
return v;
}
});
: 현재 클릭 된 마커
InfoWindow
이 예 내가 적절한
Toast
을 제시하는 경우, 내 위치를 표시하는 마커 인 경우 나 사용자가 다른 작업을 사용하여이 위치를 탐색 할 수없는 경우 다음
나는 확인
정보 창이 팝업 될 때마다 왜 OnInfoWindowClickListener를 설정 하시겠습니까? InfoWindowAdapter를 설정하는 동시에 한 번 수행하면 충분합니다. –
사실 이것은이 질문의 일부가 아니기 때문에 무시할 수 있지만, 맞습니다. –