Android Question Google Map Rotation

vfafou

Well-Known Member
Licensed User
Hello!

I need to rotate the Google Map in order to show my real direction and the position relatively with a second marker somewhere else on the map.
I think I've found the proper functions to do it but I can't succeed it.

Could anyone help me do it correctly?

Thank you in advance!
 

peacemaker

Expert
Licensed User
B4X:
Sub Follow_Map (point As Location)
    If AutoScalingForbidden Then
        Return    'pause, not allowed
    End If
   
    Dim llb As LatLngBoundsBuilder
    llb.Initialize
    Dim ll As LatLng
    ll.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude)
    llb = llb.Include(ll)
    ll.Initialize(point.Latitude, point.Longitude)
    llb = llb.Include(ll)
    GoogleMapsExtras1.AnimateToBounds(gmap, llb.Build, 200)
    Dim cp As CameraPosition
    cp.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, gps.MeI.BearingTo(Destination), 0)
    AutoScaledFlag = True
    gmap.AnimateCamera(cp)
End Sub
 
Upvote 0

Paolo Fiaschi

Member
Licensed User
B4X:
Sub Follow_Map (point As Location)
    If AutoScalingForbidden Then
        Return    'pause, not allowed
    End If
  
    Dim llb As LatLngBoundsBuilder
    llb.Initialize
    Dim ll As LatLng
    ll.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude)
    llb = llb.Include(ll)
    ll.Initialize(point.Latitude, point.Longitude)
    llb = llb.Include(ll)
    GoogleMapsExtras1.AnimateToBounds(gmap, llb.Build, 200)
    Dim cp As CameraPosition
    cp.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, gps.MeI.BearingTo(Destination), 0)
    AutoScaledFlag = True
    gmap.AnimateCamera(cp)
End Sub

Hi, what's 'Destination' variable?

Thanks
 
Upvote 0

vfafou

Well-Known Member
Licensed User
If you need to rotate towards another position, then north is not your case...
Another "technique" is keeping the previous location from GPS/FusedLocation, you can place your moving marker on road with .BearingTo(PreviousLocation).
It's up to you what exactly you need to do!
If you like, tell me your case and I'll send you the proper code!
 
Upvote 0

Paolo Fiaschi

Member
Licensed User
If you need to rotate towards another position, then north is not your case...
Another "technique" is keeping the previous location from GPS/FusedLocation, you can place your moving marker on road with .BearingTo(PreviousLocation).
It's up to you what exactly you need to do!
If you like, tell me your case and I'll send you the proper code!

Many thanks for your reply vfafou.
I'll try your suggestions.
 
Upvote 0

Sidnei Nardo

Member
Licensed User
Hi. I'm developing an application that uses map and location, I could not make the map rotate, to always go up, according to the movement of the smartphone. I think I have to make it spin automatically, but how do I know what value I should put as a parameter? Do you have any more detailed examples?
Thank you very much.
I even put this doubt into another conversation, but the answer did not help me much ..

the code I'm using is this:


'-----------------------------------------------------------------------
Sub GPS_LocationChanged (Location1 As Location)
If (vTelaAtual = "Motorista") Then
'GPS1.LocationSettingsIntent
vLatOld = vLatitude
vLongOld = vLongitude

vLatitude = Location1.Latitude
vLongitude = Location1.Longitude
vVelocidade = Location1.Speed * 3.6

vLatitude = vLatitude & "000000000000"
vLongitude = vLongitude & "000000000000"
vVelocidade = vVelocidade & "000000000000"

vLatitude = vLatitude.SubString2(0,12)
vLongitude = vLongitude.SubString2(0,12)
vVelocidade = vVelocidade.SubString2(0,12)

mfMapaMotorista_Ready

' SetBearing( Location1 )

If( (vTelaAtual = "Motorista") And (tmTempo.Enabled = False) ) Then tmTempo.Enabled= True
End If
End Sub
'-----------------------------------------------------------------------


Sub mfMapaMotorista_Ready
If( (GPS1.IsInitialized) And (vLatitude <> "") And (vLongitude <> "" )) Then
gmap = mfMapaMotorista.GetMap
gmap.Clear

Dim vVeloc As Double = vVelocidade

Dim m1 As Marker = gmap.AddMarker(vLatitude, vLongitude, pNomeExibir)

m1.Snippet = vVeloc & "KM/h"
m1.Title = pNomeExibir

Activity.title = pNomeExibir & " - " & NumberFormat( vVeloc, 0,3) & " KM/H"

Dim latlon As LatLng
latlon.Initialize(vLatitude,vLongitude)

Dim lBearingTo As Location, vBearingTo As Double
lBearingTo.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude)

vDestino.Initialize
vBearingTo = vDestino.BearingTo(lBearingTo)

gmap.MapType = gmap.MAP_TYPE_NORMAL

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.GetUiSettings.ZoomControlsEnabled = True

Dim cp As CameraPosition
cp.Initialize2( latlon.Latitude, latlon.Longitude, gmap.CameraPosition.Zoom, vBearingTo, 1)
gmap.AnimateCamera(cp)
End If
End Sub
'-----------------------------------------------------------------------
 
Upvote 0

DonManfred

Expert
Licensed User
1. Always create a new thread for any question you have. Do not post to existing threads.
2. Please use [CODE]code here...[/CODE] tags when posting code.
 
Upvote 0

wes58

Active Member
Licensed User
Hi. I'm developing an application that uses map and location, I could not make the map rotate, to always go up, according to the movement of the smartphone. I think I have to make it spin automatically, but how do I know what value I should put as a parameter? Do you have any more detailed examples?
Thank you very much.
I even put this doubt into another conversation, but the answer did not help me much ..

the code I'm using is this:


'-----------------------------------------------------------------------
Sub GPS_LocationChanged (Location1 As Location)


' SetBearing( Location1 )
I wasn't going to respond but I decided to do it, since you mentioned another thread that you posted the question in.
I gave you a solution in that thread. If it didn't work, why didn't you write in that thread, and post your code?

In your code that you posted, you have a line commented out ' SetBearing(Location1).
Is that the solution I gave you? I wrote, as far as I can remember, Location1.Bearing. Have you tried this? Didn't it work?

It's been working for me for many years. But what I do first, I check if the Bearing is valid. So my code is like this:
B4X:
     If Location1.BearingValid Then
         SetBearing( Location1.Bearing)
     End If

But Don is right, you shouldn't ask your questions in someone else's thread. The only exception (in my point of view) is a library thread!
 
Upvote 0

Sidnei Nardo

Member
Licensed User
Hi, sorry for posting on someone else's topic, I thought it would be easier to understand, I did not want to be inconvenient. I had never posted any code, so I could not post the code in the correct place. About posting in 2 places, I also apologize for this, I could not do with your suggestion, and as I saw this other conversation, apparently the same subject I decided to ask here, and I actually mentioned that I had already tried to help on another topic.
Today I was on duty at work and I could not test your suggestion, the other day, try to do it, but I did not succeed, so I went to this post. I'll test again tomorrow. Thank you and apologize again for the inconvenience.
 
Upvote 0
Top