Android Question GoogleMaps Polygons Infowindow ?

marcick

Well-Known Member
Licensed User
Longtime User
Hi all,
thanks to GoogleMapsExtras library it's easy to draw polygons on the map.
Supoosing to have many of them on the map, now I'm thinking how to add some text or infowindow to each one.
Any idea ?
 

eurojam

Well-Known Member
Licensed User
Longtime User
I use a library (polygonraycast) which determins if a point is within a polygon. then you have to loop over the polygons and get the polygon. I have two maps one with the polygon and primary key to the attributes and one with the attibutes. The whole construct is like this (may be there is an more easier way, but this works for me with a few 100 polygons...):

B4X:
Sub Map_Click (mPoint As LatLng)
    Dim f As flst
    f = inpoly(mPoint) 'check for point in poly
    Log(f)
    If f <> Null Then
        Log(f.flstkz)
        Dim s As String
       
        s = f.eigentue_1 & " " & f.eigentue_2 & CRLF & _
            "Gemarkung : " & f.gmk_name  & CRLF & _
            "Grundstücksart: " & f.grundstu_1 & CRLF & _
            "Wirtschaftsart: " & f.wirtscha_1 & CRLF & _
            "Nutzung: " & f.nutzungs_1
           
        ' Dim BitmapDescriptor1 As BitmapDescriptor
         Dim BitmapDescriptorFactory1 As BitmapDescriptorFactory
         'BitmapDescriptor1=BitmapDescriptorFactory1.DefaultMarker2(BitmapDescriptorFactory1.HUE_YELLOW)           
       
        If InfoMarker.IsInitialized Then
           InfoMarker.Remove
        End If
        InfoMarker = gmap.AddMarker2(mPoint.Latitude,mPoint.Longitude,f.flstkz, BitmapDescriptorFactory1.HUE_YELLOW)

       Dim cp As CameraPosition
       'cp.Initialize(48.706214727530195,9.060724675655365, 7)  'Baden-Württemberg
       cp.Initialize(mPoint.Latitude,mPoint.Longitude, gmap.CameraPosition.Zoom)  'Linkenheim
       gmap.AnimateCamera(cp)


        InfoMarker.Snippet=s
        InfoMarker.InfoWindowShown=True
    Else       
        If InfoMarker.IsInitialized Then
           InfoMarker.Remove
        End If
    End If
End Sub

Sub inpoly (p As LatLng) As flst 'flst is my own type holding the attibutes of each parcell

For k = 0 To pmap.Size-1 'Map with polygons....
  Dim pol As Polygon
  Dim pList  As List
  pol = pmap.GetKeyAt(k)   
  pList = pol.Points
  Dim c_raycast As PolygonRaycast
 
  Dim hit As Boolean
  c_raycast.Initialize
  hit = c_raycast.f_check_current_location(p, pList)
  If hit Then
      Dim f As flst
    Log(pmap.GetKeyAt(k))
      f =fmap.Get( pmap.GetValueAt(k)) 'map with attirbutes
      Return f

  End If
Next      

Return Null 'nothing found

End Sub

Sub Map_Ready
.....
'define the infowindow
      Dim InfoWindowAdapter1 As InfoWindowAdapter
      InfoWindowAdapter1.Initialize("InfoWindowAdapter1")
      GoogleMapsExtras1.SetInfoWindowAdapter(gmap, InfoWindowAdapter1)
      InfoWindowPanel.Initialize("")
      InfoWindowPanel.LoadLayout("MapInfoWindow")
      MapPanel.AddView(InfoWindowPanel, 0, 0, 270dip, 200dip)
      InfoWindowPanel.RemoveView

...
   End If
End Sub
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Hi. So the concept is, when you create a new polygon, to create also a marker centered on it ?
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
no, the concept is, when you click on the map, to create a marker at that position in the case a polygon is at that point. The marker is created after the click event.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Ok, we can do as we like. I didn't think to use a marker, smart idea, thanks !!
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
result looks like this:

0
 
Upvote 0
Top