Display Custom Info Window with ImageView on Google Map V2
Display Custom Info Window with ImageView on Google Map V2
To display image on Google Map V2 Bubble, we will be integrating Universal Image Loader
In Map V2, to display custom bubble, there is a InfoWindowAdapter class.
Implement the InfoWindowAdapter class and override 2 methods :
1. getInfoContents(Marker marker)
2. getInfoWindow(Marker marker)
Implement the InfoWindowAdapter class and override 2 methods :
1. getInfoContents(Marker marker)
2. getInfoWindow(Marker marker)
Set InfoWindowAdapter
googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
Store Marker id in variable with each marker image URL. So, in CustomInfoWindowAdapter class, it can be accessed using Marker Id. Fro now we will store id in Hashtable:
CustomInfoWindowAdapter
markers.put(hamburg.getId(), "http://img.india-forums.com/images/100x100/37525-a-still-image-of-akshay-kumar.jpg");Create custom_info_window.xml layout. It will be displayed when click on Marker.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/custom_info_bubble" android:orientation="horizontal" > <ImageView android:id="@+id/badge" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginRight="5dp" android:adjustViewBounds="true" > </ImageView> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:singleLine="true" android:textColor="#ff000000" android:textSize="14dp" android:textStyle="bold" /> <TextView android:id="@+id/snippet" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ff7f7f7f" android:textSize="14dp" /> </LinearLayout> </LinearLayout>
CustomInfoWindowAdapter
package com.ngshah.goglemapv2withlazyloading; import java.util.Hashtable; import android.app.ActivityManager; import android.content.Context; import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.ngshah.goglemapv2withlazyloading.R; import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; import com.nostra13.universalimageloader.cache.memory.impl.FIFOLimitedMemoryCache; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.nostra13.universalimageloader.core.assist.QueueProcessingType; import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener; public class MainActivity extends FragmentActivity { private GoogleMap googleMap; private final LatLng HAMBURG = new LatLng(53.558, 9.927); private final LatLng KIEL = new LatLng(53.551, 9.993); private Marker marker; private Hashtable<String, String> markers; private ImageLoader imageLoader; private DisplayImageOptions options; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); initImageLoader(); markers = new Hashtable<String, String>(); imageLoader = ImageLoader.getInstance(); options = new DisplayImageOptions.Builder() .showStubImage(R.drawable.ic_launcher) // Display Stub Image .showImageForEmptyUri(R.drawable.ic_launcher) // If Empty image found .cacheInMemory() .cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build(); if ( googleMap != null ) { googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter()); final Marker hamburg = googleMap.addMarker(new MarkerOptions().position(HAMBURG) .title("Hamburg")); markers.put(hamburg.getId(), "http://img.india-forums.com/images/100x100/37525-a-still-image-of-akshay-kumar.jpg"); final Marker kiel = googleMap.addMarker(new MarkerOptions() .position(KIEL) .title("Kiel") .snippet("Kiel is cool") .icon(BitmapDescriptorFactory .fromResource(R.drawable.ic_launcher))); markers.put(kiel.getId(), "http://www.yodot.com/images/jpeg-images-sm.png"); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15)); googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); } } private class CustomInfoWindowAdapter implements InfoWindowAdapter { private View view; public CustomInfoWindowAdapter() { view = getLayoutInflater().inflate(R.layout.custom_info_window, null); } @Override public View getInfoContents(Marker marker) { if (MainActivity.this.marker != null && MainActivity.this.marker.isInfoWindowShown()) { MainActivity.this.marker.hideInfoWindow(); MainActivity.this.marker.showInfoWindow(); } return null; } @Override public View getInfoWindow(final Marker marker) { MainActivity.this.marker = marker; String url = null; if (marker.getId() != null && markers != null && markers.size() > 0) { if ( markers.get(marker.getId()) != null && markers.get(marker.getId()) != null) { url = markers.get(marker.getId()); } } final ImageView image = ((ImageView) view.findViewById(R.id.badge)); if (url != null && !url.equalsIgnoreCase("null") && !url.equalsIgnoreCase("")) { imageLoader.displayImage(url, image, options, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); getInfoContents(marker); } }); } else { image.setImageResource(R.drawable.ic_launcher); } final String title = marker.getTitle(); final TextView titleUi = ((TextView) view.findViewById(R.id.title)); if (title != null) { titleUi.setText(title); } else { titleUi.setText(""); } final String snippet = marker.getSnippet(); final TextView snippetUi = ((TextView) view .findViewById(R.id.snippet)); if (snippet != null) { snippetUi.setText(snippet); } else { snippetUi.setText(""); } return view; } } private void initImageLoader() { int memoryCacheSize; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { int memClass = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass(); memoryCacheSize = (memClass / 8) * 1024 * 1024; } else { memoryCacheSize = 2 * 1024 * 1024; } final ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( this).threadPoolSize(5) .threadPriority(Thread.NORM_PRIORITY - 2) .memoryCacheSize(memoryCacheSize) .memoryCache(new FIFOLimitedMemoryCache(memoryCacheSize-1000000)) .denyCacheImageMultipleSizesInMemory() .discCacheFileNameGenerator(new Md5FileNameGenerator()) .tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging() .build(); ImageLoader.getInstance().init(config); } }
Nishant, thanks for this great example! But I have one question: imagine I would like to make my info window exactly the same as the original, and the only thing I would like to change is its background color and opacity. Do you think there would be a simpler way to do that?
ReplyDeleteHello Nishant ,
ReplyDeletePerfect example .
But i want to set googleMap.addMarker(new MarkerOptions().icon using Lazy loading .
Thanks
Parag
Hello Nishant, Thanks for your sharing.
ReplyDeleteThis is very helpful for me.
Thanks!
Nice tutorial..pls add the date when it is posted... :)
ReplyDeleteNot work for Multiple marker
ReplyDeleteThanks for solution... Point is that on UniversalImageLoader and onLoadingComplete(), call getInfoContents(marker) and after it calls rerun infoWindow with loaded image... :)
ReplyDeletegetInfoWindow() -> onLoadingComplete() -> getInfoContents(marker). This call comes in loop as showInfoWindow() again call getInfoWindow. This increases memory consumption and GC get called continuously.
ReplyDeleteinstaead of calling getInfoContents(marker) explicitly, image.setImageBitmap(loadedImage) will work perfect.
This comment has been removed by the author.
Deletehi is there any way to get data in info window at multiple marker different data load from list
ReplyDeleteHi!
ReplyDeleteThanks for your sharing,
But I have problem in code:
markers.put(hamburg.getId(), "http://img.india-forums.com/images/100x100/37525-a-still-image-of-akshay-kumar.jpg");
I want picture url is a SDcard url...How do I change code?
Thanks for all the help!
Help me! Please
Delete@drawable/custom_info_bubble is missing
ReplyDeleteHi
ReplyDeleteThanks for sharing your code but i have a problem with onclick on textview in infowindow,Is it possible to make textview as a clickable in Infowindow?
* Project GogleMapV2WithLzyLoading:/home/jenya1/Downloads/GogleMapV2WithLzyLoading-master/project.properties:
ReplyDeleteLibrary reference ../google-play-services_lib could not be found
Path is /home/jenya1/Downloads/GogleMapV2WithLzyLoading-master/../google-play-services_lib which resolves to /home/jenya1/Downloads/google-play-services_lib
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeletepython training in Bangalore
I'm here representing the visitors and readers of your own website say many thanks for many remarkable
ReplyDeleteTableau online training
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeleteSql server dba online training
Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it..
ReplyDeleteOracle DBA Online Training
Quickbooks Integration
ReplyDeletenice blog
ReplyDeleteget best placement at VSIPL
get digital marketing and web development service
seo network point
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
ReplyDeleteSoftware testing online training
Software testing certification training
Software testing online course
Software testing training course
Thanks for sharing it.I got Very valuable information from your blog.your post is really very Informatve. I got Very valuable information from your blog.I’m satisfied with the information that you provide for me.
ReplyDeletePython Training in Pune
Python Classes
Python Placement
Python Institute Pune
Python courses
Nice post
ReplyDeleteFor Python training in Bangalore, Visit:
Python training in Bangalore
Thank you for your guide to with upgrade information
ReplyDeleteData Science online Training
Android training
Dot net Course
Informatica Online Training
iOS development course
tableau certification
This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information.python training in bangalore
ReplyDeleteThanks for your excellent blog and giving great kind of information. So useful. Nice work keep it up thanks for sharing the knowledge.
ReplyDeleteDevops training in Pune with placement
Thanks for the informative stuff....
ReplyDeletelearn tableau
I am a regular reader of your blog and I find it really informative. Hope more Articles From You.Best Tableau tutorial video available Here. hope more articles from you.
ReplyDeleteThanks a lot for sharing it, that’s truly has added a lot to our knowledge about this topic. Have a more success ful day. Amazing write-up, always find something interesting and here i want to share some thing about mulesoft training hyderabad .
ReplyDeleteThanks for posting such an informative stuff...
ReplyDeleteaws tutorial videos
Thanks for your excellent blog and giving great kind of information. So useful. Nice work keep it up thanks for sharing the knowledge.
ReplyDeleteVisit us
Click Here
For More Details
Visit Website
Thanks for your excellent blog and giving great kind of information. So useful. Nice work keep it up thanks for sharing the knowledge.
ReplyDeleteVisit us
Click Here
For More Details
Visit Website
See More
Such a terrific facts for blogger i am a professional blogger thanks…
ReplyDeleteclick here formore info.
Nice post. Thanks for sharing! I want humans to understand simply how excellent this facts is to your article.
ReplyDeleteIt’s thrilling content material and Great work.
isaimini movies hd
Thanks for sharing such an useful info...
ReplyDeleteLearn Tableau Online
Thanks for sharing it.I got Very valuable information from your blog.your post is really very Informative.I’m satisfied with the information that you provide for me.Software testing is a process ensure that the product is defect free.By reading your blog, i get inspired and this provides some useful information. Keep it up and best of luck for your future blogs posts.
ReplyDeletesoftware testing institute in pune at 3ri Technologies
Thanks for sharing it.I got Very valuable information from your blog.your post is really very Informative.I’m satisfied with the information that you provide for me.Nice post. By reading your blog, i get inspired and this provides some useful information.
ReplyDeletesap mm training in pune with placement
After I initially commented I seem to have clicked on the -Notify me when new comments are
ReplyDeleteadded- checkbox and now every time a comment is added I receive 4 emails with the exact same comment.
There has to be an easy method you are able to remove me from that service? Kudos!
Click here to more info.
I think this is one of the most important info for me.And i am glad reading your article. But want to remark on few general things, The site style is good , the articles is really excellent and also check Our Profile for
ReplyDeletesql training courses and sql server training videos.
Thanks for sharing this information. I really Like Very Much.
ReplyDeletemulesoft esb online training in hyderabad
mulesoft online training institutes
mulesoft online training and certification
ReplyDeleteThis post is really nice and informative. The explanation given is really comprehensive and informative. I want to share some information about the best oracle dba training and oracle weblogic tutorial training videos. Thank you .Hoping more articles from you.
Thanks for the informative article About Reactjs. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this servicenow training , I feel happy about it and I love learning more about this topic.
ReplyDeleteI simply want to give you a huge thumbs up for the great info you have got here on this post.
ReplyDeleteSoftware Testing Training in Chennai | Software Testing Training in Anna Nagar | Software Testing Training in OMR | Software Testing Training in Porur | Software Testing Training in Tambaram | Software Testing Training in Velachery
Thanks for sharing such informative guide on .Net technology. This post gives me detailed information about the .net technology.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
I use Facebook, along with Twitter and YouTube, as an important piece of my social media strategy. I have made many great contacts on Facebook, and usually log in a couple of times a day. Resurge Diet Supplement
ReplyDeleteThanks for sharing with us that awesome article you have amazing blog..............
ReplyDeleteWeb Designing Course Training in Chennai | Certification | Online Course Training | Web Designing Course Training in Bangalore | Certification | Online Course Training | Web Designing Course Training in Hyderabad | Certification | Online Course Training | Web Designing Course Training in Coimbatore | Certification | Online Course Training | Web Designing Course Training in Online | Certification | Online Course Training
Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You !
ReplyDeleteAWS training in Chennai
AWS Online Training in Chennai
AWS training in Bangalore
AWS training in Hyderabad
AWS training in Coimbatore
AWS training
AWS online training
Thank you for your guide.
ReplyDeleteI got a new things with upgrade information.
java training in chennai
java training in porur
aws training in chennai
aws training in porur
python training in chennai
python training in porur
selenium training in chennai
selenium training in porur
ReplyDeleteWow. That is so elegant and logical and clearly explained. Brilliantly goes through what could be a complex process and makes it obvious.I want to refer about the best msbi training in hyderabad
Good Post! , it was so good to read and useful to improve my knowledge as an updated one, keep blogging.After seeing your article I want to say that also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
ReplyDeletehttps://www.3ritechnologies.com/course/mern-stack-training-in-pune/
Good Post! , it was so good to read and useful to improve my knowledge as an updated one, keep blogging. After seeing your article I want to say that also a well-written article with some very good information which is very useful for the AWS Cloud Practitioner Online Training
ReplyDeleteThanks for this valuable piece of information... Saved the day.
ReplyDeleteAlso sharing hands to help for DevOps Online Training
Nice Blog. Check this Ethical hacking course in bangalore
ReplyDeleteNice post. Chekc this Ethical Hacking Certification Course in Banaglore
ReplyDeleteThanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
ReplyDeletetop mulesoft online training
Thanks for your excellent blog and giving great kind of information. So useful. Nice work keep it up thanks for sharing the knowledge.
ReplyDeleteDevOps Training in Chennai
DevOps Course in Chennai
Nice Article!
ReplyDeleteMedical Coding Course
Java Course
Php Course
Dot Net Course
React Js Course
Ground Staff Course
Cabin Crew Course
Clinica Research Courses
Data Science Course
Air Hostess Course
Software Testing Course
Good Post! , it was so good to read and useful to improve my knowledge as an updated one, keep blogging. After seeing your article I want to say that also a well-written article with some very good information which is very useful for the readers.thanks for sharing it and do share more posts like this.
ReplyDeleteIT Training in Pune with placements
IT Training in Pune
The content of this website was really informative. 50 High Quality Backlinks for just 50 INR
ReplyDelete2000 Backlink at cheapest
5000 Backlink at cheapest
Boost DA upto 15+ at cheapest
Boost DA upto 25+ at cheapest
Boost DA upto 35+ at cheapest
Boost DA upto 45+ at cheapest
Autocad Training in Bangalore
ReplyDeleteAutocad classes in Bangalore
Keto Pills are the most popular type of weight loss product and chances are you’ve probably seen advertisements for keto products by now. These keto pure diet pills may help enhance your weight loss, boost your energy levels, and can make it easier for you to stick to your keto diet. Many of the most popular keto products contain exogenous ketones – ketones made outside of the body. These ketones are the fuel that your body burns instead of carbohydrates when you are on the keto diet. Check now the full Keto pure diet pills reviews for clear your doubt with full information. Some keto products may contain one or many other natural ingredients that may help boost your metabolism in addition to these exogenous ketones.
ReplyDeleteI’m glad you like my post! I learned many new things myself
ReplyDeleteby cloudi5 is the digital marketing company in coimbatore
Actually your blog is very interesting; it contains extraordinary and remarkable data. I appreciated visiting your blog…
ReplyDeleteDevOps Training in Hyderabad
thank you for sharing we are looking forward for more
ReplyDeleteaws Training in Hyderabad
I really enjoy the blog article.Much thanks again.
ReplyDeleteBest Data Science Online Training
Data Science Online Training
Hey there
ReplyDeleteThanks for sharing this example, Keep on updating more informative article like this
Best web development company
Best Software Development company
Mobile app development company
well, thats a great blog. Really so much impressive and i love that type of post. thank you.
ReplyDeleteIf you ssearching for a legit financial service .Check it out. Link below.
Unclaimed Mystery Box
deep web money transfer
legit paypal transfer dark web
darknet paypal transferpa
dark web financial services .
Please carry on and keep blogging . Thanks again
Thank For sharing Valuable Information
ReplyDeleteMulesoft Training in Hyderabad
Mulesoft Online Training in India
Otdr Machine
ReplyDeleteonline video downloader
ReplyDeleteyoutube downloader
instagram downloader
facebook downloader
twitter downloader
vimeo downloader
tiktok downloader
perde modelleri
ReplyDeletesms onay
mobil ödeme bozdurma
Nft Nasıl Alınır
ANKARA EVDEN EVE NAKLİYAT
trafik sigortası
dedektör
WEB SİTESİ KURMA
aşk kitapları
함안출장마사지 창녕출장마사지 고성출장마사지
ReplyDelete남원출장마사지 군산출장마사지 전주출장마사지
ReplyDeleteThis comment has been removed by the author.
ReplyDelete함평군출장샵
ReplyDelete영광군출장샵
장성군출장샵
신안군출장샵
완주군출장샵
진안군출장샵
This comment has been removed by the author.
ReplyDeleteindustrial training institute
ReplyDeletewow what is this really? Why aren't you doing this now? I think it's so awesome and awesome I have to 서울출장아로마
ReplyDelete인천출장아로마
세종출장아로마
서귀포출장아로마 share this with my friends and my son and wife right now I feel like I found an oasis in the desert Thank you so much for finding your site.
Really Nice Article! You post inspire me too much.
ReplyDeletelottery sambad from lotterysambad24hr.com
wordpress website design agency in united states Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today!
ReplyDeleteThanks for your excellent blog and giving great kind of information. So useful. Nice work keep it up thanks for sharing the knowledge.
ReplyDeleteHot Foil Stamping Machine
Sweet Box Making Machine
Die Punching Machine in India
This comment has been removed by the author.
ReplyDeleteVery Important Logic for us...
ReplyDeleteweb development course in amritsar
The ultimate aim of installing ransomware into your system is to demand a lumpsum amount from you in the form of ransom. It may ask you to buy the Xhamster file decryption tool available online at an exorbitant price. xhamster ransomware
ReplyDeleteGet counselling sessions right away if you need assistance with an addiction.
ReplyDeleteBest Rehab Center in India
https://www.masterbet288.com/
ReplyDeleteAre you looking to elevate your travel with Asiana Airlines? Need help on How to cancel and refund at Asiana Airlines Flight? For assistance, contact Asiana Airlines at OTA+1 800 970 3794 (no wait).
ReplyDeleteHow to cancel and refund at Asiana Airlines Flight?