我制作了一个自定义信息窗口,显示5个信息(医院名称,地址,传真,移动和固定电话),我在按下时使用标题和片段成功显示了医院和地址,但没有显示最后3个数据。一些博客说我应该使用Hashmap来显示额外的数据,但我对他们的样本感到困惑。
标记代码:
ArrayList<MapConstants> _list = new ArrayList<MapConstants>(); _list.addAll(GlobalVariablesClass.FOR_MAPMARKER);
for (int i = 0; i < _list.size(); i++) {
MarkerOptions markerOption = (new MarkerOptions().position(new LatLng(Double.valueOf(_list.get(i).getLatitude()), Double.valueOf(_list.get(i).getLongitude()))).title(bla).snippet(bla).icon(bla);
}
答案 0 :(得分:0)
我通过这样做解决了我的问题:
1st:我创建了一个类,我将在其中存储webservice的返回并将其用于标记。 (mapConstants.Class)
MapConstants.Class:
公共类MapConstants {
grugroupid groupbname accesstype
----------------------------------
1 group-1 1
2 group-2 (null)
3 group-3 (null)
4 group-4 (null)
}
第二:关于你制作标记的方法(在我的例子中是addmarkersToMapNew()),我创建了一个Hashmap,它将存储除title和Snippet之外你需要的其他数据。
addMarkersToMapNew():
private String CLINIC_NAME, CLINIC_CODE, UNIT_NO
,BLDG_NAME, STREET, COUNTRY, LATITUDE, LONGITUDE, LANDLINE, MOBILE, FAX;
public MapConstants()
{
}
public MapConstants (String ClinicName, String ClinicCode, String UnitNo, String BuildingName
, String Street, String Country, String Latitude, String Longitude, String Landline, String Mobile, String Fax)
{
CLINIC_NAME = ClinicName;
CLINIC_CODE = ClinicCode;
UNIT_NO = UnitNo;
BLDG_NAME = BuildingName;
STREET = Street;
COUNTRY = Country;
LATITUDE = Latitude;
LONGITUDE = Longitude;
LANDLINE = Landline;
MOBILE = Mobile;
FAX = Fax;
}
public String setClinicName() {
return this.CLINIC_NAME;
}
public String getClinicName() {
return this.CLINIC_NAME;
}
public String setClinicCode() {
return this.CLINIC_CODE;
}
public String getClinicCode() {
return this.CLINIC_CODE;
}
public String setUnitNo() {
return this.UNIT_NO;
}
public String getUnitNo() {
return this.UNIT_NO;
}
public String setBldgName() {
return this.BLDG_NAME;
}
public String getBldgName() {
return this.BLDG_NAME;
}
public String setStreet() {
return this.STREET;
}
public String getStreet() {
return this.STREET;
}
public String setCountry() {
return this.COUNTRY;
}
public String getCountry() {
return this.COUNTRY;
}
public String setLatitude() {
return this.LATITUDE;
}
public String getLatitude() {
return this.LATITUDE;
}
public String setLongitude() {
return this.LONGITUDE;
}
public String getLongitude() {
return this.LONGITUDE;
}
public String setMobile(){
return this.MOBILE;
}
public String getMobile(){
return this.MOBILE;
}
public String setLandline(){
return this.LANDLINE;
}
public String getLandline(){
return this.LANDLINE;
}
public String setFax(){
return this.FAX;
}
public String getFax(){
return this.FAX;
}
第三:在我保存了我需要在Hashmap(extraMarkerInfo)中显示的其他数据后,我现在可以声明我的自定义信息窗口:
自定义信息窗口:
类MyInfoWindowAdapter实现InfoWindowAdapter {
private void addMarkersToMapNew()
{
//TODO addMarkersToMapNew
int markerCount = 0;
//ProgressDialog progDailog = null;
if (ConnectionEcardMessage.isConnectingToInternet(SearchMapFragmentActivity.this))
{
ArrayList<MapConstants> _list = new ArrayList<MapConstants>();
_list.addAll(GlobalVariablesClass.FOR_MAPMARKER);
Log.i("addMarkersToMapNew-size", ""+_list.size());
Log.i("addMarkersToMapNew", "ConnectionEcardMessage.isConnectingToInternet(SearchMapFragmentActivity.this)");
if (mMapMarkers == null)
{
Log.i("addMarkersToMapNew", "null");
mMapMarkers = new HashMap<String, MarkerOptions>();
extraMarkerInfo = new ArrayList<HashMap<String, String>>();
EcardMessage.appendLog("SearchMapFrag 6.5 - get curBranchDetails");
for (int i = 0; i < _list.size(); i++)
{
HashMap<String, String> contactHashmap = new HashMap<String, String>();
Log.d("myApp", "added branch " + _list.get(i).getClinicName());
MarkerOptions markerOption = (new MarkerOptions()
.position(
new LatLng(Double.valueOf(_list.get(i).getLatitude()),
Double.valueOf(_list.get(i).getLongitude())))
.title(_list.get(i).getClinicName()) .snippet(_list.get(i).getUnitNo()+""+_list.get(i).getBldgName()+","+_list.get(i).getStreet()+", "+_list.get(i).getCountry())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.address)));
Log.i("Latitude_At_Longitude", "EDI WOW");
contactHashmap.put("landline", _list.get(i).getLandline() );
Log.i("kay landline", _list.get(i).getLandline());
contactHashmap.put("mobile", _list.get(i).getMobile() );
Log.i("kay Mobile", _list.get(i).getMobile());
contactHashmap.put("fax", _list.get(i).getFax() );
Log.i("kay Fax", _list.get(i).getFax());
contactHashmap.put("title", _list.get(i).getClinicName());
Log.i("kay title", _list.get(i).getClinicName());
extraMarkerInfo.add(contactHashmap);
mMapMarkers.put("Marker" + ++markerCount, markerOption);
mMap.addMarker(markerOption);
}
}
}