Android Question GoogleMaps Polygons Infowindow ?

Discussion in 'Android Questions' started by marcick, Nov 6, 2015.

  1. marcick

    marcick Well-Known Member Licensed 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 ?
     
  2. eurojam

    eurojam Well-Known Member Licensed 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...):

    Code:
    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 LatLngAs 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, 
    00270dip200dip)
          InfoWindowPanel.RemoveView

    ...
       
    End If
    End Sub
     
    An Schi and marcick like this.
  3. marcick

    marcick Well-Known Member Licensed User

    Hi. So the concept is, when you create a new polygon, to create also a marker centered on it ?
     
  4. eurojam

    eurojam Well-Known Member Licensed 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.
     
  5. marcick

    marcick Well-Known Member Licensed User

    Ok, we can do as we like. I didn't think to use a marker, smart idea, thanks !!
     
  6. eurojam

    eurojam Well-Known Member Licensed User

    result looks like this:

    [​IMG]
     
  7. marcick

    marcick Well-Known Member Licensed User

    can't see it ..
     
  8. eurojam

    eurojam Well-Known Member Licensed User

    ups sorry:
    unnamed.png
     
  9. marcick

    marcick Well-Known Member Licensed User

    Good. Thanks again.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice