我正在使用 Android 谷歌地图,我正在使用 MapApiV2。我能够在地图上显示地图、用户位置、标记。我的问题是,当用户单击地图上的任何标记时,我想打开一个 InfoWindow。我也可以打开窗口,但我需要在信息视频中显示更多数据,所以我试图在 .snippet() 方法中传递我的 CustomClass 对象,但它除了字符串对象之外。因此,我只需执行此操作 (uv.tostring) 并将我的类对象转换为字符串并传递给 snippet() 方法。现在,当我尝试使用 marker.getSnippt() 从片段中获取 dat 时;我无法从字符串中访问我的数据。所以请建议我如何将我的自定义类对象传递给 snippt,以便我可以访问我的自定义类的 get、set 方法。
下面是我的代码我的自定义类是:
public class UserVerifyer implements UserVerfierInterface{
// <userPojo>
// <frequency>0.0</frequency>
// <message/>
// <status>NOTOK</status>
// <token>ey0dok0vozrhwhe98rt6ydbs</token>
// <url/>
// </userPojo>
private String frequency = "", message = "", status = "", token = "",
url = "";
public static String statusOk = "OK";
public void setFrequency(String freq) {
this.frequency = freq;
}
public String getFrequency() {
return frequency.trim();
}
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message.trim();
}
public void setStatus(String status) {
this.status = status;
}
public String getStatus() {
return status.trim();
}
public void setToken(String token) {
this.token = token;
}
public String getToken() {
return token.trim();
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return url.trim();
}
}
MyCustomInfo 窗口类是:
公共类 CustomMarkers 实现 InfoWindowAdapter {
// private Context context;
// private String text;
// private Integer image;
private final View mWindow;
private final View mContents;
public CustomMarkers(Activity activity) {
// this.context = ctx;
// this.text = text;
// this.image = image;
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mWindow = inflater.inflate(R.layout.balloon, null);
mContents = inflater.inflate(R.layout.balloon, null);
}
@Override
public View getInfoContents(Marker marker) {
// TODO Auto-generated method stub
render(marker, mWindow);
return mWindow;
}
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
render(marker, mContents);
return mContents;
}
private void render(Marker marker, View view) {
String title = marker.getTitle();
TextView titleUi = ((TextView) view.findViewById(R.id.txtTitle));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}
String snippet = marker.getSnippet();
UserVerifyer uv = UserVerifyer.class.cast(snippet);
System.out.println("Sttaus in Marker= "+uv.getStatus());
// uv.getStatus();
TextView snippetUi = ((TextView) view.findViewById(R.id.txtPlace));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}
}
}
我正在像这样在标记中添加数据:
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(getMyLocation().getLatitude(),
getMyLocation().getLongitude())).zoom(17).bearing(90)
.tilt(30).build();
mMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
UserVerifyer uv = new UserVerifyer();
mMap.addMarker(new MarkerOptions()
.position(
new LatLng(getMyLocation().getLatitude(),
getMyLocation().getLongitude()))
.title("Me")
.snippet(uv.toString())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.user_loc)));
mMap.setInfoWindowAdapter(new CustomMarkers(RecomendationScreen.this));
请建议我该怎么做。
谢谢。