enter image description here我正在开发一个地图应用程序,该应用程序通过来自JSON的经度和纬度添加标记。每个纬度和经度也会附带其他信息。我已将此信息存储到数组列表中。标记显示的是确切位置,但是当我尝试在有关标记位置的Google标记单击中将此信息显示到自定义对话框时出现问题,值显示为空。如何解决这个问题呢?
我的MarkerHolder类
public class MarkerHolder {
public String bunch_jobName;
public String addess;
public String destiny;
public String note;
public MarkerHolder(String bunch_jobName, String addess, String destiny, String note) {
bunch_jobName = bunch_jobName;
addess = addess;
destiny = destiny;
note = note;
}
}
GoogleMap.setOnMarkerClickListener(new com.google.android.gms.maps.GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker){
cal = new Dialog(activity);
cal.setCanceledOnTouchOutside(true);
cal.requestWindowFeature(Window.FEATURE_NO_TITLE);
cal.getWindow().setBackgroundDrawable(new ColorDrawable(0));
cal.setContentView(R.layout.marker_popup_info);
cal.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
TextView stops_name = cal.findViewById(R.id.tv_stops_name);
TextView stops_addr = cal.findViewById(R.id.tv_stops_address);
TextView stops_destination = cal.findViewById(R.id.tv_destiny);
TextView stops_note = cal.findViewById(R.id.tv_note);
MarkerHolder mHolder = markerHolderMap.get(marker.getId());
stops_name.setText(mHolder.bunch_jobName);
stops_addr.setText(mHolder.bunch_jobName);
stops_destination.setText(mHolder.bunch_jobName);
stops_note.setText(mHolder.bunch_jobName);
cal.show();
return false;
}
});
在JSON中使用
MarkerOptions选项=新的MarkerOptions(); options.position(new LatLng(location_lat1,location_longi1));
Marker marker = GoogleMap.addMarker(options);
MarkerHolder mHolder = new MarkerHolder(task_job_name,job_merchant,contact_no,task_address);
markerHolderMap.put(marker.getId(), mHolder);