I have been having a hard time trying to load url from Google Map Api
into Google Maps Marker
with Async Task.
How do I correctly get this image loading library to load icons from google map api into the markers being shown in my custom map.
What is the best way to achieve this?
public class GetNearbyPlaces extends AsyncTask<Object, String,String> {
@Override
protected String doInBackground(Object... objects) {
mMap = (GoogleMap) objects[0];
String url = (String) objects[1];
DownloadUrl downloadUrl = new DownloadUrl();
try {
googlePlaceData = downloadUrl.ReadTheURL(url);
} catch (IOException e) {
e.printStackTrace();
}
return googlePlaceData;
}
private void DisplayNearbyPlaces(List<HashMap<String, String>> nearbyPlacesList){
for (int i = 0; i<nearbyPlacesList.size(); i++){
MarkerOptions markerOptions = new MarkerOptions();
//load image icon from url
String url = googleNearbyPlace.get("icon");
loadMarkerIcon(url);
}
}
private void loadMarkerIcon(final Marker marker, final String url) {
Glide.with(context).load(url)
.asBitmap().fitCenter().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(bitmap);
marker.setIcon(icon);
}
});
}
}