レイアウト ファイルを作成した情報ウィンドウのカスタマイズされたビューを作成しようとしています。しかし、私のデータ(緯度と経度)はArrayListの形式です。
for (int i = 0; i < list.size(); i++) {
Log.e(getClass().getName(), list.get(i).getFirstName());
double x = list.get(i).getLocationLatLon().getLat();
double y = list.get(i).getLocationLatLon().getLon();
if (x > 90 || x < -90 || y < -180 || y > 180) {
Log.e(getClass().getName(),
"out of range " + Double.toString(x) + " "
+ Double.toString(y));
lng2 = new LatLng(lat, lng);
} else {
Log.e(getClass().getName(),
"In range " + Double.toString(x) + " "
+ Double.toString(y));
lng2 = new LatLng(x, y);
}
InfoClass infoClass= new InfoClass();
infoClass.setName(list.get(i).getFirstName()+" "+list.get(i).getLastName());
infoClass.setCharge(list.get(i).getCharge());
infoClass.setAvailableTime(list.get(i).getTimeAvailable());
infoClass.setServiceCategory(list.get(i).getCategoryName());
infoClass.setServiceName(list.get(i).getServiceName());
finalist.add(infoClass);
theMap.addMarker(new MarkerOptions()
.title(list.get(i).getServiceName())
.position(lng2)
.icon(BitmapDescriptorFactory
.fromResource(entertainment))
.snippet(list.get(i).getFirstName() + " "+ list.get(i).getLastName()) );
theMap.setOnInfoWindowClickListener(this);
}
リストの緯度と経度に従ってマーカーを設定し、クラス InfoClass の ArrayList に必要な情報を追加しています。ここで setInfoWindowAdapter を設定し、ファイナリストを InfoWindowAdapter の実装に渡します。
theMap.setInfoWindowAdapter(new InfoWindow(this, finalist));
私のInfoWindowクラス
public class InfoWindow implements InfoWindowAdapter {
private final View myContentsView;
private LayoutInflater mInflator;
ArrayList<InfoClass> list;
public InfoWindow(Context context, ArrayList<InfoClass> list) {
//Context context = new MainActivity().getApplicationContext();
Context context2= context;
mInflator = LayoutInflater.from(context2);
this.list= list;
myContentsView = mInflator.inflate(R.layout.info_view, null);
}
@Override
public View getInfoWindow(Marker marker) {
return myContentsView;
}
@Override
public View getInfoContents(Marker arg0) {
return null;
}
}
getInfoWindow メソッドでは、各マーカーが Location に基づいて個別の情報を表示する必要があるため、特定のマーカーの情報を取得するにはどうすればよいですか。