Polyline with infowindow in android app
Asked Answered
F

3

6

In android map application, it shows tool-tip window for multiple route, the same way google map also shows that window. I was wondering whether that is a custom marker or a infoWindow over poly-line.

Does any body knows how to achieve this with android map-v2 integration?

Following image show my expectations to implement in android.

Snapshot from google map

Formalism answered 3/11, 2016 at 6:2 Comment(0)
L
4

2020 Solution (Kotlin)

I wrote this little Kotlin extension function (simply add to your extension functions or anywhere in your code) to do exactly the job needed: It adds an info window half way on the polyline.

fun Polyline.addInfoWindow(map: GoogleMap, title: String, message: String) {
    val pointsOnLine = this.points.size
    val infoLatLng = this.points[(pointsOnLine / 2)]
    val invisibleMarker =
        BitmapDescriptorFactory.fromBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888))
    val marker = map.addMarker(
        MarkerOptions()
            .position(infoLatLng)
            .title(title)
            .snippet(message)
            .alpha(0f)
            .icon(invisibleMarker)
            .anchor(0f, 0f)
    )
    marker.showInfoWindow()
}

Use as follows:

polyline.addInfoWindow(map, "Title", "Message")

Example use:

polyline.addInfoWindow(map, route.distanceText, route.durationText)

enter image description here

Levulose answered 12/6, 2020 at 16:25 Comment(0)
B
1

In the Google Maps Android API it says that:

An info window displays text or images in a popup window above the map. Info windows are always anchored to a marker. Their default behavior is to display when the marker is tapped.

Therefore, you will either have to use another solution than just attaching an info window to the polyline. Maybe you can create an invisible marker at the location, the polyline has been clicked, on the fly which opens the info window.

Broch answered 3/11, 2016 at 7:57 Comment(1)
There are problems with this solution: 1. You cannot create multiple infowindows at the same time. 2. You don't know how to place the tooltips so they lay out separately.Khosrow
L
0

In case someone is still looking for an answer, you can use bubble icons from the maps-utils library. It lets you create customized markers, that look just like infowindows. You can run a demo from here, but make sure you import is as a project when you run it: File->New->Import Project...

Lite answered 13/9, 2017 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.