Android Question How to Rotate a marker in Google Map as per Road Direction

AndroidMadhu

Active Member
Licensed User
Hello,
I am trying a custom marker to rotate as per Road Direction in GMAP.
I am following the below link......
https://www.b4x.com/android/forum/threads/google_maps-marker-rotate.66242/

But the above link is not working. I am getting below error while loading the custom marker icon
B4X:
actmap$ResumableSub_Activity_Resumeresume (java line: 859)
java.lang.RuntimeException: Object should first be initialized (BitmapDrawable).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.drawable.BitmapDrawable.getBitmap(BitmapDrawable.java:39)
at b4a.example.gmapstest.actmap$ResumableSub_Activity_Resume.resume(actmap.java:859)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:190)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6820)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:922)

The below is the code for load of custom marker:
B4X:
Markeropts.Initialize
Markeropts.Position2(search.pickupLocation.Latitude,search.pickupLocation.Longitude).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)


Please advice as how to rotate a custom market as per Road direction.

Thanks
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
Better to use a previously loaded bitmap

Very Simple:


B4X:
Private xui AS XUI

Public GoogleMapsExtras1 As GoogleMapsExtras
Public MarkerExtras1 As MarkerExtras

Public BitmapCar As B4XBitmap
Public Marker1 As Marker

B4X:
BitmapCar = xui.LoadBitmapResize(File.DirAssets, "car.png", 24dip, 24dip, True)

B4X:
Marker1 = GoogleMap1.AddMarker3(LastLocation.Latitude, LastLocation.Longitude, Null, BitmapCar)

Note:
LastLocation = Is the Last Location or next Location
B4X:
MarkerExtras1.SetRotation(Marker1, LastLocation.Bearing)

;););)

Regards.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Hello,
@oparra ... I have fixed some of the issue regarding the rotation of Marker in GMAP.
I have used the below parameter
B4X:
Dim   mx As MarkerExtras
mx.SetRotation(mrkr(vhlMarkerId),newloc.BearingTo(lastLocation))

But while I am back to the source [From where I started] the car head is not moving to the source location. It seems that I am parking the car at back gear.

Please advice.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
your custom marker (bitmap) should point north.
So that the rotation of your marker indicates the direction (0-360).
 
Upvote 0
Top