gpt4 book ai didi

android - 设置 InfoWindowAdapter 仅显示单击第一个标记的信息

转载 作者:太空狗 更新时间:2023-10-29 16:05:48 25 4
gpt4 key购买 nike

所以,我已经为我的 Google map 设置了 infowindowadapter,但问题是,当我点击第一个标记时,它会正确显示信息,但是当我点击第二个标记时,它会显示信息从第一个开始,所以 infowindowadapter 不会刷新。

谁能告诉我为什么会这样以及如何解决?

我正在关注这篇文章以设置 infowindowadapter:

custom info window adapter with custom data in map v2

编辑:

    new getMarkers().execute();

mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
return false;
}
});
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}

@Override
public View getInfoContents(Marker marker) {

View view = getLayoutInflater().inflate(R.layout.post_details_on_map,null);

date = (TextView)view.findViewById(R.id.txtMarkerDate);
comment = (TextView)view.findViewById(R.id.txtMarkerComment);
image = (ImageView)view.findViewById(R.id.ivMarkerPicture);

MyMarkerInfo mmi = markerMap.get(marker.getId());
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id",mmi.getId()));

MarkerDetails mDetails = new JSONAdapter().getMarkerDetails(params);
date.setText(mDetails.getDate());
comment.setText(mDetails.getComment());

new getPicture().execute(mDetails.getImageUrl());
return view;
}
});

最佳答案

这是我的完全相同操作的代码:

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

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;
}
}
/*
findDirections(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude(),
SGTasksListAppObj.getInstance().currentUserLocation.getLongitude(),
clickMarkerLatLng.latitude, clickMarkerLatLng.longitude, GMapV2Direction.MODE_DRIVING );
*/
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;

}
});

我的猜测是您以错误的方式获取其他标记信息。尝试比较我的方法和您的方法,并尝试记录过程以查看您是否传递了正确的 ID 并获取了正确的信息。

关于android - 设置 InfoWindowAdapter 仅显示单击第一个标记的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15684805/

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