Android Question Google Map Rotation

Discussion in 'Android Questions' started by vfafou, Jul 16, 2017.

  1. vfafou

    vfafou Active Member Licensed User


    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!
  2. Erel

    Erel Administrator Staff Member Licensed User

    You need to create a CameraPosition object with Initialize2. It allows you to set the bearing.
  3. peacemaker

    peacemaker Well-Known Member Licensed User

    Sub Follow_Map (point As Location)
    If AutoScalingForbidden Then
    Return    'pause, not allowed
        End If
    Dim llb As LatLngBoundsBuilder
    Dim ll As LatLng
        ll.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude)
        llb = llb.Include(ll)
    point.Latitude, point.Longitude)
        llb = llb.Include(ll)
        GoogleMapsExtras1.AnimateToBounds(gmap, llb.Build, 
    Dim cp As CameraPosition
        cp.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, 
    gps.MeI.BearingTo(Destination), 0)
        AutoScaledFlag = 
    End Sub
    vfafou likes this.
  4. vfafou

    vfafou Active Member Licensed User

    Thank you very very much peacemaker! It's working like a charm! ;)
  5. Paolo Fiaschi

    Paolo Fiaschi Member Licensed User

    Hi, what's 'Destination' variable?

  6. vfafou

    vfafou Active Member Licensed User

    @Paolo Fiaschi
    Hello Paolo!
    It's the Location object of the destination.
  7. Paolo Fiaschi

    Paolo Fiaschi Member Licensed User

    I see!. 'relatively with a second marker somewhere else on the map' as you said.
    So this is useless to select to setting map fixed to north or rotate map to follow my direction, isn't?
  8. vfafou

    vfafou Active 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!
  9. Paolo Fiaschi

    Paolo Fiaschi Member Licensed User

    Many thanks for your reply vfafou.
    I'll try your suggestions.
  10. Sidnei Nardo

    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
    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)


    ' 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

    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

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

    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)
    End If
    End Sub
  11. DonManfred

    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.
  12. wes58

    wes58 Active Member Licensed User

    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:
    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!
    DonManfred likes this.
  13. Sidnei Nardo

    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.
  14. Sidnei Nardo

    Sidnei Nardo Member Licensed User

    Eu fiz o teste, aparentemente funcionou, estou adaptando o resto do projeto e farei mais testes. Muito obrigado.
  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