![](/img/trans.png)
[英]OSMDroid/OSMBonusPack adding marker with info bubble on marker click
[英]android: not getting info on marker click
我在數據庫中有四個條目,我正在使用 retrofit 獲取所有數據。 API 工作正常我正在獲取所有必要的數據。 我想在標記單擊時顯示用戶姓名、地址、號碼和技能(來自數據庫)並將它們設置在自定義警報對話框中。
問題
當我點擊任何標記時,我只會得到最后一個條目。 在每個標記infoWindowClickListener
上,我每次只得到相同的名稱、地址、號碼和技能。 我也用標記保存索引,但我不知道如何使用該索引。
我想要的是?
每個標記都應顯示自己的信息。 任何人都可以幫助我在onInfoWindowClickListener
方法中應該做什么來獲取與每個標記關聯的確切信息。 如果您不太了解,請隨時提出任何問題。
MapFragment.java:
public void onMapReady(final GoogleMap mMap) {
mGoogleMap = mMap;
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(0);
mLocationRequest.setFastestInterval(0);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
fetchLastLocation();
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
ApiInterface apiInterface2 = ApiClient.getClient().create(ApiInterface.class);
Call<AllDataResponse> call2 = apiInterface2.allLabours("showAds");
call2.enqueue(new Callback<AllDataResponse>() {
@Override
public void onResponse(Call<AllDataResponse> call, Response<AllDataResponse> response) {
if (response.body() != null) {
if (response.body().isError_bol()) {
String errosr = response.body().getError_message();
Toast.makeText(getActivity(), errosr, Toast.LENGTH_SHORT).show();
} else {
labourDataAlls = response.body().getAll_labours();
if (labourDataAlls != null) {
latLngData.addAll(labourDataAlls);
Log.v("TAaG", "LOGS" + latLngData.size());
for (int i = 0; i < latLngData.size(); i++) {
double lat = Double.parseDouble(latLngData.get(i).getLb_latitude());
double lng = Double.parseDouble(latLngData.get(i).getLb_longitude());
Str_lb_name = latLngData.get(i).getLb_name();
Str_lb_phone = latLngData.get(i).getLb_phone();
Str_lb_address = latLngData.get(i).getLb_address();
Str_lb_skill = latLngData.get(i).getLb_skills();
drawMarker(new LatLng(lat, lng), i);
}
Log.d("setr", String.valueOf(list));
Toast.makeText(getActivity(), "No Error", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Unknown Error Occurs", Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
public void onFailure(Call<AllDataResponse> call, Throwable t) {
Toast.makeText(getContext(), "" + t.toString(), Toast.LENGTH_SHORT).show();
}
});
mMap.setOnInfoWindowClickListener(this);
mMap.setMyLocationEnabled(true);
}
private void drawMarker(final LatLng point , final int index){
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(point).title(labourDataAlls.get(index).getLb_name()+index);
mGoogleMap.addMarker(markerOptions);
}
@Override
public void onInfoWindowClick(Marker marker) {
}
向 googleMap 添加標記時的 setTag(index)
private void drawMarker(final LatLng point , final int index){
private Marker marker;
marker = mGoogleMap.addMarker(new MarkerOptions()
.position(point)
.title(labourDataAlls.get(index).getLb_name()+index);
marker.setTag(index);
}
@Override
public void onInfoWindowClick(Marker marker) {
int index = (int)(marker.getTag());
//Use index get Value from labourDataAlls
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.