I am unable to add the icon provided by the Google Places API to the marker. For example, I would like to have the icon returned from the JSON of Google Places API:
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"
Here's how I am doing it now without adding the icon:
for (Place place : mNearPlaces.results) {
LatLng placeLatLng = new LatLng(place.geometry.location.lat,
map.addMarker(new MarkerOptions()
.position(placeLatLng)
.title(place.name));
}
I looked at this post and the answer suggested using some AsyncTask to download the image. Is there any other way to do this (that way seems slow)? Is there a standard way of setting the marker image provided by the Google Places API?
Here is the Google Maps Android API v2 Documentation for Markers
Thanks
Hi use a librariy that help you to view images from URL. visit https://github.com/nostra13/Android-Universal-Image-Loader for Android-Universal-Image-Loader
also you can visit to know for downloading the image
http://brainflush.wordpress.com/2009/11/23/droid-fu-part-2-webimageview-and-webgalleryadapter/
and after that
for the Custom Marker Icon, you can use an icon to show as a marker. load the icon from any kind of supported sources.
fromAsset(String assetName) – Loading from assets folder
fromBitmap (Bitmap image) – Loading bitmap image
fromFile (String path) – Loading from file
fromResource (int resourceId) – Loading from drawable resource
try as follows
You can load url image to a GoogleMap mapMarker using following code. First set other properties like title, snippet, position etc....
After use a custom method to load a image for icon property. You can add Glide gradle link to project.
there are a lot of libraries that help you view images from URL like: URLImageViewhelper unfortunately, you can't load images from URL without
AsyncTask
however all the libraries that help you view images from URL are usingAsynctask
so only you have to do is call the function.the implementation of the library class are available within the github page.