Android Question Google_Maps Marker Rotate

prajinpraveen

Active Member
Licensed User
Longtime User
Hello, i am trying to create a marker with custom image and would like the image to rotate according to the direction/bearing of the street (eg Uber). please guide
 

Attachments

  • tempFile_2016-04-25-20-46-08.jpg
    tempFile_2016-04-25-20-46-08.jpg
    111.2 KB · Views: 457

eurojam

Well-Known Member
Licensed User
Longtime User
this code snipplet rotates a marker. How you will get the bearing of the street? will you use OSM for that?
B4X:
    Dim GoogleMapsExtras1 As GoogleMapsExtras
    Dim AndroidResources1 As AndroidResources
    Dim BitmapDescriptor1 As BitmapDescriptor
    Dim BitmapDescriptorFactory1 As BitmapDescriptorFactory
    Dim Icon As Bitmap
    Dim Mydrawable1 As BitmapDrawable
    Dim Markeropts As MarkerOptions

    Markeropts.Initialize
    Markeropts.Position2(48,9).Snippet("").Title("").Visible(True)
    Mydrawable1=AndroidResources1.GetApplicationDrawable("icon1")
    Icon=Mydrawable1.Bitmap
    BitmapDescriptor1=BitmapDescriptorFactory1.FromBitmap(Icon)
    Markeropts.Icon(BitmapDescriptor1)
    Markeropts.Rotate(45)  'Rotate the marker
    Dim Marker1 As Marker=GoogleMapsExtras1.AddMarker(gmap, Markeropts)
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
Thank you for the reply. Would it be possible to get the angle/bearing of the street so that we can rotate the marker accordingly. So everytime the street's direction changes, marker is rotated . Not sure if I am making my question clear. See screenshot in the first post
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
1) if you have 2 adresses in the street e.g. Chambers Street no 6 / Chambers Street no 8 you can geocode the adresses (with googlegeocode api) and then calculate the bearing of the 2 points...
2) you have the vector data of the streets (OpenStreetMap), then you can calculate the bearing from the vector data
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
used location class, and worked like a charm


Dim LocationFrom As Location
Dim LocationTo as Location

LocationTo.Initialize2(routeto.Latitude,routeto.Longitude)
LocationFrom.Initialize2(routebegin.Latitude,routebegin.Longitude)
rotateangle =LocationFrom.BearingTo(LocationTo)
 
Upvote 0
Top