I'm using Google Maps in my app with few markers. Every few seconds I'm loading from API markers positions. Each marker has set title and snippet. In snippet I would like to display time when data was loaded.
Problem is that when user clicked on one of the markers and InfoWindow
with title and snippet is visible then after that I change the snippet & the content but the content on visible InfoWindow
is not changed - user has to click on the map to hide InfoWindow
and click again on marker - then the content is correct.
Is it possible to refresh InfoWindow
content after title or snippet has changed?
An InfoWindow displays content (usually text or images) in a popup window above the map, at a given location. The info window has a content area and a tapered stem. The tip of the stem is attached to a specified location on the map. Info windows appear as a Dialog to screen readers.
An InfoWindow can be placed on a map at a particular position or above a marker, depending on what is specified in the options. Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map.
By assigning the infowindow to a marker property, each marker can have it's own infowindow. This was how I approached the problem, with the relevant sample code. //create a marker object first, or instantiate it by passing a JSON to the constructor. //this can be done inside a for loop var infowindow = new google.
I found solution using Android Maps Extensions https://github.com/mg6maciej/android-maps-extensions.
Call this after update markers data:
Marker m = map.getMarkerShowingInfoWindow();
if (m != null && !m.isCluster()) {
m.showInfoWindow();
}
Take note that in the documentation of Google Maps Android API that:
The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (for example, after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
Then, if you want to do realtime functionality. I suggest learning how to use Firebase with Google maps.
What is Firebase?
Firebase is an application platform with many features. This tutorial uses its Realtime Database. Data is stored as JSON, is synced to all connected clients in real time, and is available even when your app goes offline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With