Android Question Googlemaps CameraChanged

Discussion in 'Android Questions' started by Roger Daley, May 22, 2015.

  1. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hi All,

    I am trying to detect when a Google map is changed. IE Dragged, rotated or zoomed. It is fairly clear that the Google Maps "CameraChanged" feature is the key but I am unable to find out how to do this. Below is my feeble attempt at guess working the solution.
    Can someone please point me to an example, I am sure there are some somewhere on the forum.

    Code:
    Sub mFragmentListener_CameraChanged(Position As CameraPosition)
        
    Log("CameraChanged")
        Projection1=GoogleMapsExtras1.GetProjection(gmap)
        MarkerLocation = BTSMarker.Position
        ScreenPosition = Projection1.toScreenLocation(MarkerLocation)
        XX = ScreenPosition.X
        YY = ScreenPosition.Y
    ' Other stuff
    End Sub
    Regards Roger
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    Hello Roger,
    here is a small example. when the user zoom in to a higher level then maxzoom the map zooms back to maxzoom...

    Code:
    Sub Globals
       
    Dim mFragment As MapFragment
       
    Dim gmap As GoogleMap
       
    Dim GoogleMapsExtras1 As GoogleMapsExtras
       
    Dim maxZoom As Double = 10
       
    Dim MapPanel As Panel
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
       MapPanel.Initialize(
    "")
       
    Activity.AddView(MapPanel, 00100%x80%y)
       
    If mFragment.IsGooglePlayServicesAvailable = False Then
          
    ToastMessageShow("Google Play services not available."True)
       
    Else
          mFragment.Initialize(
    "Map", MapPanel) 'the event for the camera is Map_CameraChange (Position As CameraPosition)
       End If
    End Sub
    Sub Map_Ready

       
    Log("map ready")
       gmap = mFragment.GetMap
       
    If gmap.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
       
    Else
         gmap.MapType=gmap.MAP_TYPE_TERRAIN
         gmap.MyLocationEnabled = 
    True
       
         
    'goto SW germany
         Dim cp As CameraPosition
         cp.Initialize(
    48.706214727530195,9.0607246756553657)
         gmap.AnimateCamera(cp)   
       
       
    End If
    End Sub

    Sub Map_CameraChange (Position As CameraPosition)
       
    Log("Zoom " & gmap.CameraPosition.Zoom)
       
    'If zoomlevel Is greater Then Max zoom Then zoomout
       Dim CameraUpdateFactory1 As CameraUpdateFactory
       
    Dim CameraUpdate1 As CameraUpdate
      
    If gmap.CameraPosition.Zoom > maxZoom Then
         CameraUpdate1=CameraUpdateFactory1.ZoomTo(maxZoom)
         GoogleMapsExtras1.AnimateCamera(gmap, CameraUpdate1)
      
    End If

    End Sub
     
    Roger Daley likes this.
  3. Roger Daley

    Roger Daley Well-Known Member Licensed User

    eurojam,

    Magic stuff, thanks for the code.
    Just to pick your brains once more, the action occurs after the map is moved etc. Do you know if its possible to have it update dynamicaly as in "AnyDragListener_Drag(Marker1 As Marker)" type event?
    I am moving Imageviews with the map movement and as it is at the moment the images play catch-up. I can live with this but dynamicaly would be nice.

    Code:
    Sub Map_CameraChange (Position As CameraPosition)
       
    'Log("Zoom " & gmap.CameraPosition.Zoom)
        Projection1=GoogleMapsExtras1.GetProjection(gmap)
      
        MarkerLocation = BTSMarker.Position
        ScreenPosition = Projection1.toScreenLocation(MarkerLocation)
        BTSX = ScreenPosition.X
        BTSY = ScreenPosition.Y
        BTSIV.Left = BTSX - BTSIV.Width/
    2
        BTSIV.Top = BTSY - BTSIV.Height/
    2
      
        MarkerLocation = LANDMarker.Position
        ScreenPosition = Projection1.toScreenLocation(MarkerLocation)
        LMX = ScreenPosition.X
        LMY = ScreenPosition.Y
        LMIV.Left = LMX - LMIV.Width/
    2
        LMIV.Top = LMY - LMIV.Height/
    2
    End Sub
    Thanks again
    Regards Roger
     
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