Android Question GoogleMaps === CameraChange Event

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

  1. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hi All

    The CameraChange event when the map is dragged appears to fire only after the action is complete. Is there a way to fire the event as the map is being moved? This would be in effect a CamerChanging Event rather than a CameraChanged event.

    Perhaps I need to put this in the wish list forum.

    Any ideas welcomed.

    Regards Roger
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Roger Daley likes this.
  3. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks Erel,

    Regards Roger
     
  4. warwound

    warwound Expert Licensed User

    You'll find the b4a GoogleMaps documentation here:
    http://www.b4x.com/android/help/googlemaps.html#mapfragment
    There's no event raised while the camera position is being changed - only after it has been changed.

    You could make this a feature request BUT before you do that look at the android GoogleMaps documentation:
    https://developers.google.com/android/reference/com/google/android/gms/maps/package-summary
    Look under the 'Interfaces' section where you'll see the available listeners.
    The documentation for the OnCameraChangeListener states:

    There is no android listener for 'camera position changing', so there's no way b4a could implement such a listener.
     
    Roger Daley likes this.
  5. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks Warwound

    I will do some reading.

    Regards Roger


    Reading done. Added my vote to an existing feature request. Request has been in the system for over two and a half years so I won't hold my breath.

    RWD.
     
    Last edited: Jun 4, 2015
  6. Daniel Corpus

    Daniel Corpus New Member

    Hello,

    So was this topic solved? is it posible in B4A to have a live changing position?
     
  7. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Daniel,

    Issue solved in the sense of post #4 by warwound. [Worth reading the links]

    Short answer. No! The request from developers for "CamerChanging Event" has been with Google for some years but with no response.

    Roger
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    The (native) map doesn't raise any event until the movement is complete. There is nothing that can be solved as this is how the native map works.

    You can easily use a timer if it is important to your app.

    This is not related to live changing position which is of course possible.
     
  9. Daniel Corpus

    Daniel Corpus New Member


    Thanks Erel,

    I have used a timer as you suggested and it is almost working.. the problem is that the timer cannot configure for microseconds or use an timer array to get it.. and this is causing a lag efect in the refreshing of my marker

    Bu the way, I am trying to have a static marker in the middel of the map/panel.

    Do you know about other option to do this?

    Thanks and regards.
     
  10. eurojam

    eurojam Well-Known Member Licensed User

  11. rscheel

    rscheel Well-Known Member Licensed User

    I did this a while ago with effect test, but never materialized anything, I hope you serve.

    Code:
    Sub Process_Globals
        
    Dim GPS As GPS
    End Sub

    Sub Globals
        
    Dim mFragment As MapFragment
        
    Dim gmap As GoogleMap
        
    Dim MapPanel As Panel
        
    Dim Latitud As Double = 0
        
    Dim Longitud As Double = 0
        
    Dim Lat2 As Double = 0
        
    Dim Lon2 As Double = 0 
        
    Dim p1, p2 As Location
        
    Dim Distance As Float
        
    Dim boton1, boton2, boton3, boton4, boton5, boton6 As Button
        
    Dim tb As ToggleButton
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    Activity.AddMenuItem("Menú""")
        
    Activity.AddMenuItem("Salir""Exit")
        
    GPS.Initialize("GPS")
        MapPanel.Initialize(
    "")
        
    Activity.AddView(MapPanel, 00100%x100%y)
     
        
    'Boton velocidad'
        boton1.Initialize(0)
        boton1.Text = 
    0 &" "&"km/h"
        boton1.TextColor = 
    Colors.Red
        boton1.TextSize = 
    15
        
    Activity.AddView(boton1, 40%x5dip25%x40dip)
        
    'Fin Boton velocidad'
     
        
    'Toggle mostrar ocultar'
        tb.Initialize("tb")
        
    'Dim checked, unchecked As ColorDrawable
        Dim checked, unchecked As BitmapDrawable
        checked.Initialize(
    LoadBitmap(File.DirAssets,"add182.png"))
        unchecked.Initialize(
    LoadBitmap(File.DirAssets,"up151.png"))
        
    'checked.Initialize(Colors.Green, 10dip)
        'unchecked.Initialize(Colors.Red, 10dip)
        Dim sld As StateListDrawable
        sld.Initialize
        sld.AddState(sld.State_Unchecked, unchecked)
        sld.AddState(sld.State_Checked, checked)
        tb.Background = sld
        tb.TextOff = 
    ""
        tb.TextOn = 
    ""
        tb.Checked = 
    True
        
    'tb.TextColor = Colors.Blue
       ' tb.TextSize = 10
        'tb.Typeface = Typeface.DEFAULT_BOLD
        Activity.AddView(tb, 10dip50dip11%x40dip)
        
    'Toggle mostrar ocultar'
     
        
    Dim sdBt2 As StateListDrawable
        sdBt2.Initialize
        
    Dim bd1Bt2, bd2Bt2 As BitmapDrawable
        bd1Bt2.Initialize(
    LoadBitmap(File.DirAssets, "accident-128.png"))
        bd2Bt2.Initialize(
    LoadBitmap(File.DirAssets, "checked8.png"))
        sdBt2.AddState(sdBt2.State_Pressed, bd2Bt2)
        sdBt2.AddCatchAllState(bd1Bt2)
        boton2.Initialize(
    "boton2")
        boton2.Visible = 
    False
        
    Activity.AddView(boton2, 20dip100dip11%x40dip)
        boton2.Background = sdBt2
     
        
    Dim sdBt3 As StateListDrawable
        sdBt3.Initialize
        
    Dim bd1Bt3, bd2Bt3 As BitmapDrawable
        bd1Bt3.Initialize(
    LoadBitmap(File.DirAssets, "img-pav-resb.png"))
        bd2Bt3.Initialize(
    LoadBitmap(File.DirAssets, "checked8.png"))
        sdBt3.AddState(sdBt3.State_Pressed, bd2Bt3)
        sdBt3.AddCatchAllState(bd1Bt3)
        boton3.Initialize(
    "boton3")
        boton3.Visible = 
    False
        
    Activity.AddView(boton3, 20dip150dip11%x40dip)
        boton3.Background = sdBt3
     
     
        
    Dim sdBt4 As StateListDrawable
        sdBt4.Initialize
        
    Dim bd1Bt4, bd2Bt4 As BitmapDrawable
        bd1Bt4.Initialize(
    LoadBitmap(File.DirAssets, "car-copy-141057655684kng.png"))
        bd2Bt4.Initialize(
    LoadBitmap(File.DirAssets, "checked8.png"))
        sdBt4.AddState(sdBt4.State_Pressed, bd2Bt4)
        sdBt4.AddCatchAllState(bd1Bt4)
        boton4.Initialize(
    "boton4")
        boton4.Visible = 
    False
        
    Activity.AddView(boton4, 20dip200dip11%x40dip)
        boton4.Background = sdBt4
     
        
    Dim sdBt5 As StateListDrawable
        sdBt5.Initialize
        
    Dim bd1Bt5, bd2Bt5 As BitmapDrawable
        bd1Bt5.Initialize(
    LoadBitmap(File.DirAssets, "24143.png"))
        bd2Bt5.Initialize(
    LoadBitmap(File.DirAssets, "checked8.png"))
        sdBt5.AddState(sdBt5.State_Pressed, bd2Bt5)
        sdBt5.AddCatchAllState(bd1Bt5)
        boton5.Initialize(
    "boton5")
        boton5.Visible = 
    False
        
    Activity.AddView(boton5, 20dip250dip11%x40dip)
        boton5.Background = sdBt5
     
        
    Dim sdBt6 As StateListDrawable
        sdBt6.Initialize
        
    Dim bd1Bt6, bd2Bt6 As BitmapDrawable
        bd1Bt6.Initialize(
    LoadBitmap(File.DirAssets, "cow9.png"))
        bd2Bt6.Initialize(
    LoadBitmap(File.DirAssets, "checked8.png"))
        sdBt6.AddState(sdBt6.State_Pressed, bd2Bt6)
        sdBt6.AddCatchAllState(bd1Bt6)
        boton6.Initialize(
    "boton6")
        boton6.Visible = 
    False
        
    Activity.AddView(boton6, 20dip300dip11%x40dip)
        boton6.Background = sdBt6

           
    If mFragment.IsGooglePlayServicesAvailable = False Then
          
    ToastMessageShow("Google Play services not available."True)
           
    Else
          mFragment.Initialize(
    "Map", MapPanel)
          
    End If
    End Sub

    Sub Exit_click
            
    ExitApplication
    End Sub

    Sub tb_CheckedChange(Checked As Boolean)
        
    If Checked Then
            
    'ToastMessageShow( "ON", True)
            boton2.Visible = False
            boton3.Visible = 
    False
            boton4.Visible = 
    False
            boton5.Visible = 
    False
            boton6.Visible = 
    False
        
    Else
            
    'ToastMessageShow( "OFF", True)
            boton2.Visible = True
            boton3.Visible = 
    True
            boton4.Visible = 
    True
            boton5.Visible = 
    True
            boton6.Visible = 
    True
        
    End If
    End Sub

    Sub boton2_Click
            tb.Checked = 
    True
    End Sub
    Sub boton3_Click
            tb.Checked = 
    True
    End Sub
    Sub boton4_Click
            tb.Checked = 
    True
    End Sub
    Sub boton5_Click
            tb.Checked = 
    True
    End Sub
    Sub boton6_Click
            tb.Checked = 
    True
    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_NORMAL
        gmap.MyLocationEnabled = 
    True
        gmap.GetUiSettings.MyLocationButtonEnabled =
    True
        gmap.GetUiSettings.TiltGesturesEnabled = 
    True
        gmap.GetUiSettings.ZoomGesturesEnabled = 
    True
        gmap.GetUiSettings.CompassEnabled = 
    True
        gmap.GetUiSettings.RotateGesturesEnabled = 
    True
        
    'gmap.TrafficEnabled = True
        Dim cp As CameraPosition
        
    'gmap.AddMarker(Parametro.Latitude, Parametro.Longitude, "Ubicación")
        cp.Initialize(-33.469119900000000000 , -70.64199700000000000015)
        gmap.AnimateCamera(cp)
        
    End If
    End Sub

    Sub GPS_LocationChanged (Parametro As Location)
        
    Dim sp As Int
        sp = 
    Ceil(Parametro.Speed * 3.6)
        boton1.Text = sp &
    " "&"km/h"
        Latitud = Parametro.Latitude
        Longitud = Parametro.Longitude
        p2.Initialize2(Latitud,Longitud)
        p1.Initialize2(Lat2, Lon2)
        Distance  = p1.DistanceTo(p2)
        
    If Latitud <> 0 And Longitud <> 0 Then
        
    If Distance > 10 Then
        Lat2 = Latitud
        Lon2 = Longitud
        
    Dim cp As CameraPosition
        gmap.AddMarker(-
    36.5942989, -72.0995082"Terrazza Nostra")
        
    'gmap.AddMarker(-36.5935292, -72.10382900000002, "Inacap Chillán")
        'gmap.AddMarker3(-36.5935292, -72.10382900000002, "Inacap Chillán", LoadBitmap(File.DirAssets, "24143.png"))
        Dim Marker1 As Marker
        
    Dim Markers As Map
        Markers.Initialize
        Marker1=gmap.AddMarker(-
    36.5935292, -72.10382900000002"Inacap Chillán")
        Marker1.Snippet = 
    "Intituto Inacap Chillán (Universidad Tecnologica de Chile ."
        Markers.Put(Marker1, Marker1)
        gmap.AddMarker(-
    36.5923074, -72.10404399999999"Easy Chillán")
        gmap.AddMarker(-
    36.59566679999999, -72.10702659999998"Jumbo Chillán")
        gmap.AddMarker(-
    35.4173139, -72.3472667"Camur")
        gmap.AddMarker(-
    35.3775215, -72.3916733"Iván Uribe")
        gmap.AddMarker(-
    35.372909, -72.397079"Aserradero Martin")
        cp.Initialize2(Parametro.Latitude, Parametro.Longitude, gmap.CameraPosition.Zoom, Parametro.Bearing, 
    0)
        gmap.AnimateCamera(cp)
        
    End If
        
    End If
    End Sub

    Sub Activity_Resume
        
    If GPS.GPSEnabled = False Then
            
    ToastMessageShow("Debe Activar el GPS del Equipo."True)
            
    StartActivity(GPS.LocationSettingsIntent) 'Will open the relevant settings screen.
        Else
            
    GPS.Start(00'Listen to GPS with no filters.
        End If
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        
    GPS.Stop
    End Sub
     
    Last edited: Jan 27, 2016
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