2
我想在地圖上添加多個標記,每個標記都有自己的infowindow(我需要infowindow才能在多行顯示一些信息),但是我沒有了解如何做到這一點。 我已閱讀過Google文檔,現在我正在尋找示例代碼或教程。 任何人都可以幫助我嗎?谷歌地圖Api v2-多個標記與他們自己的infowindow
我想在地圖上添加多個標記,每個標記都有自己的infowindow(我需要infowindow才能在多行顯示一些信息),但是我沒有了解如何做到這一點。 我已閱讀過Google文檔,現在我正在尋找示例代碼或教程。 任何人都可以幫助我嗎?谷歌地圖Api v2-多個標記與他們自己的infowindow
看看這段代碼,有評論解釋我的行爲。但是,這會從預定義的XML佈局爲您創建InfoWindow
,您必須在運行時創建填充。
我檢查當前點擊的標記InfoWindow
是一個標記,表示我的位置,如果是在我提出一個適當的Toast
的,如果不是我讓用戶使用其他活動導航到該位置:
// 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;
}
});
爲什麼要在每次彈出信息窗口時都設置OnInfoWindowClickListener?在您設置InfoWindowAdapter的同時完成一次就足夠了。 – 2013-04-06 17:08:00
其實這不是問題的一部分,可以忽略,但我想你是對的... – 2013-04-06 17:22:34