B4J Question Google Maps Camera Reposition Speed

RichardN

Well-Known Member
Licensed User
Longtime User
Is it possible to change the speed at which the GoogleMaps Camera position and Zoom value move from one viewpoint to another? Using a Timer it is possible to fix the interval between position changes but not the lightning fast pan between one location and the next.
 

RichardN

Well-Known Member
Licensed User
Longtime User
@Erel

Sadly the two methods, 'panTo' and CameraPosition appear to exhibit exactly the same behavior at the same speed.
 

Attachments

  • Map Zoom Animation.zip
    2.5 KB · Views: 164
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
@Erel

The Javascript for Google Maps API does not appear to expose a native method for changing the camera pan rate.

There is some interesting discussion on a workaround for this issue on Stack Overflow but I'm not entirely sure that the required information is exposed by the jGoogleMaps lib. It could be very useful for animating 'fly-bys' with Google Maps..... See what you think....
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
You can use this routine to move the camera with animation.
or modify the animation of zoom, angle, etc.

B4X:
Sub btnCameramoveToCairo_Click
    Dim cp As CameraPosition
    cp.Initialize(Cairo.Latitude,Cairo.Longitude,10)
    MoveCameraPositionAnimation(gMap, cp, 1500)
End Sub
B4X:
Public Sub MoveCameraPositionAnimation(TargetGoogleMap As GoogleMap, TargetPosition As CameraPosition, Duration As Int)
    Dim CurrentPosition As CameraPosition = TargetGoogleMap.CameraPosition
    Dim StartTime As Long = DateTime.Now
    Do While DateTime.Now < StartTime + Duration
        Dim f As Float = (DateTime.Now - StartTime) / Duration
        Dim Latitude As Double = CurrentPosition.target.Latitude + f * (TargetPosition.Target.Latitude - CurrentPosition.Target.Latitude)
        Dim Longitude As Double  = CurrentPosition.Target.Longitude + f * (TargetPosition.Target.Longitude - CurrentPosition.Target.Longitude)
        Dim CameraPosition1 As CameraPosition
        CameraPosition1.Initialize(Latitude, Longitude, CurrentPosition.Zoom)
        TargetGoogleMap.MoveCamera(CameraPosition1)
        Sleep(100)
    Loop
    TargetGoogleMap.MoveCamera(TargetPosition)
End Sub
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Thanks @TILogistic - It works, kind of....

In my reference quoted above for the conversation on Stack Overflow there is much discussion around the subject. In effect, if both locations are simultaneously visible on the map (by virtue of the Zoom value) then we can presume that those map tiles are already cached. Repositioning the Camera in that case, using the native code produces a acceptable animated look..... as long as you don't change the zoom value as that would necessitate loading another set of tiles. If both locations are far apart and not simultaneously in view then both the CameraPosition method and @TILogistic's code produce a poor result as the tiles cannot be loaded quickly enough. Despite a very capable Graphics card and a 500mb/s internet connection the JVM simply cannot display the tiles fast enough to produce an animated look.

Having said that.... I realise I may be asking too much of the JVM. My PC is a very high-spec workstation driving a native 4k monitor and I am displaying at full screen. So I tried the same test on my very average laptop with a simple HD monitor. Playing around with the Duration and Sleep(value) produced better results but not anything that represents an acceptable user experience. We seem to have hit the limitations of the JVM.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Thanks @TILogistic - It works, kind of....

In my reference quoted above for the conversation on Stack Overflow there is much discussion around the subject. In effect, if both locations are simultaneously visible on the map (by virtue of the Zoom value) then we can presume that those map tiles are already cached. Repositioning the Camera in that case, using the native code produces a acceptable animated look..... as long as you don't change the zoom value as that would necessitate loading another set of tiles. If both locations are far apart and not simultaneously in view then both the CameraPosition method and @TILogistic's code produce a poor result as the tiles cannot be loaded quickly enough. Despite a very capable Graphics card and a 500mb/s internet connection the JVM simply cannot display the tiles fast enough to produce an animated look.

Having said that.... I realise I may be asking too much of the JVM. My PC is a very high-spec workstation driving a native 4k monitor and I am displaying at full screen. So I tried the same test on my very average laptop with a simple HD monitor. Playing around with the Duration and Sleep(value) produced better results but not anything that represents an acceptable user experience. We seem to have hit the limitations of the JVM.
If you want better display performance, you should develop a web APP
ex. leafletjs
the advantage that it is not only limited to google map, you can use other map services

Search:
 
Upvote 0
Top