gpt4 book ai didi

android - Google Maps Api v2 - 具有自己的信息窗口的多个标记

转载 作者:行者123 更新时间:2023-11-29 01:54:44 25 4
gpt4 key购买 nike

我想在 map 上添加多个标记,每个标记都有自己的信息窗口(我需要信息窗口在多行上显示一些信息),但我不知道该怎么做。我已经阅读了 Google 文档,现在我正在寻找示例代码或教程。谁能帮帮我?

最佳答案

看看这段代码,有解释我的行为的注释。但这将从预定义的 XML 布局为您创建一个 InfoWindow,您必须在运行时创建一个填充。

接下来我检查当前点击的标记 InfoWindow 是否是指示我位置的标记,如果是,我会呈现一个正确的 Toast,如果不是,我让用户使用另一个 Activity 导航到此位置:

        // 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;

}
});

关于android - Google Maps Api v2 - 具有自己的信息窗口的多个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15853119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com