I have four entries in database, I'm fetching all data using retrofit. API is working fine I'm getting all necessary data. I want to show users name, address, number and skills (Coming from database) on marker click and set them in custom alert dialog.
Issue
When I click on any marker I am getting only last entry. Mean on each marker infoWindowClickListener
I am only getting same name, address, number and skills every time.
I also save index with marker but I don’t know how to work with that index.
What I want?
Each marker should display its own info.
Anyone can help me what should I do inside onInfoWindowClickListener
method to get the exact info associated with each marker.
Please feel free to ask anything if you don’t understand well.
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) {
}