Android Question GoogleMaps === CameraChange Event

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
 

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:

Called after the camera position has changed. During an animation, this listener may not be notified of intermediate camera positions. It is always called for the final position in the animation.
There is no android listener for 'camera position changing', so there's no way b4a could implement such a listener.
 

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:

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
 

Daniel Corpus

New Member
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.

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.
 

rscheel

Well-Known Member
Licensed User
I did this a while ago with effect test, but never materialized anything, I hope you serve.

B4X:
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, 0, 0, 100%x, 100%y)
 
    'Boton velocidad'
    boton1.Initialize(0)
    boton1.Text = 0 &" "&"km/h"
    boton1.TextColor = Colors.Red
    boton1.TextSize = 15
    Activity.AddView(boton1, 40%x, 5dip, 25%x, 40dip)
    '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, 10dip, 50dip, 11%x, 40dip)
    '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, 20dip, 100dip, 11%x, 40dip)
    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, 20dip, 150dip, 11%x, 40dip)
    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, 20dip, 200dip, 11%x, 40dip)
    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, 20dip, 250dip, 11%x, 40dip)
    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, 20dip, 300dip, 11%x, 40dip)
    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.641997000000000000, 15)
    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(0, 0) 'Listen to GPS with no filters.
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    GPS.Stop
End Sub
 
Last edited:
Top