Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps snippet auto update in InfoWindow

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?

like image 415
user3626048 Avatar asked Aug 11 '16 07:08

user3626048


People also ask

What is InfoWindow in Google map?

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.

How do you change the InfoWindow position on Google Maps?

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.

How do I show multiple Infowindows on Google Maps?

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.


2 Answers

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();
    }
like image 67
user3626048 Avatar answered Nov 15 '22 04:11

user3626048


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.

like image 34
noogui Avatar answered Nov 15 '22 03:11

noogui