【发布时间】:2019-06-07 05:52:05
【问题描述】:
我有一个应用程序,它将从数据库中显示地图上的一些位置。一切正常,但我不想在我的自定义信息窗口中显示评分栏。我尝试了一些教程,但问题是我使用 php 从 JSON 获取数据。它可以工作,但默认情况下,评级栏是从数据库中检索到的最后一个信息。
这是我的课,实现GoogleMap.InfoWindowAdapter
public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private Activity context;
private int rating;
private RatingBar RTB;
public CustomInfoWindowAdapter(Activity context,int rating){
this.context = context;
this.rating=rating;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = context.getLayoutInflater().inflate(R.layout.customwindow, null);
RTB = (RatingBar) view.findViewById(R.id.mark_rating);
TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
TextView tvSubTitle = (TextView) view.findViewById(R.id.tv_subtitle);
RTB.setRating(rating);
tvTitle.setText(marker.getTitle());
tvSubTitle.setText(marker.getSnippet());
return view;
}
这是我添加标记的地方
for(int i=0 ; i<response.length();i++){
JSONObject person = (JSONObject) response.get(i);
String name = person.getString("nom");
String long_i = person.getString("longitude");
String lat_i = person.getString("latitude");
int rating = person.getInt("rating");
mMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(lat_i) , Double.parseDouble(long_i)))
.title(name)
.snippet("Nothing")
.icon(BitmapDescriptorFactory
.fromBitmap(resizeMapIcons("doctor_icon",85,85))));
CustomInfoWindowAdapter adapter = new CustomInfoWindowAdapter(MapsActivity.this,rating);
mMap.setInfoWindowAdapter(adapter);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(23.6850,90.3563), 6.0f));
}
对于布局文件,我有 2 个 textview 和 1 个 ratingBar
【问题讨论】:
-
自定义信息窗口到底是什么问题?
标签: android google-maps