Android Question Move and Rotate of Custom Marker as Per Road Direction

AndroidMadhu

Active Member
Licensed User
Hello,
I am trying to move Custom Marker as per road direction in google map.
The marker is moving successfully, but the head of the car [custom marker] is not moving to the forward direction.
I want to move the head of the car dynamically as per road direction and curve of Road
Attach screenshot for your better understanding....



Please advice as how to align the head of the car at forward direction as as per route direction [As per polyline].

Thanks
 

emexes

Expert
Licensed User
Probably simpler and better to align it with the movement of the vehicle, assuming that your plan is for the vehicle icon to move along the route per regular gps position updates from the vehicle.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
hello,
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 what I am facing is "When I am back to the source the marker head is not moving towards the location."

Please advice
 
Upvote 0

emexes

Expert
Licensed User
When I am back to the source the marker head is not moving towards the location."
I don't understand your question, but perhaps what is happening is that you get two location reports that are very close together and the bearing calculation gets confused.

A quick solution to this would be to only update the vehicle icon rotation when it has moved more than d metres from the last time the rotation was updated.

A better solution would be to go to www.flightradar24.com and click on a moving plane so that you can see its trail and how it is updated. They've done a good job of turning sporadic position updates into movement that looks realtime, even if occasionally the plane does make some funny jumps especially when turning.
 
Upvote 0

emexes

Expert
Licensed User
That sounds like lastLocation is set once to be the source location, and isn't being updated as new positions are received from the vehicle gps.

Perhaps log time, newloc, lastLocation and BearingTo() each time the vehicle icon rotation is updated. That might give us a clue why it's not working as expected.
 
Upvote 0

emexes

Expert
Licensed User
only update the vehicle icon rotation when it has moved more than d metres from the last time the rotation was updated
where d is significantly greater than the random wobble error of gps readings, eg 20-50 metres would be good
 
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

emexes

Expert
Licensed User
or do you want to do this:
Lol I've been in dodgem cars that travel more smoothly than that.

But it was a great example of vehicles being constrained to the road; in real life, the GPS readings are going to be out by more than the width of the road (especially when moving) and thus vehicles will be driving through front yards and into buildings and sliding off bends in the road... which isn't all bad, because the comedy aspect will keep eyeballs glued to the screen. ?
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Post a project of what you are doing.
To help and know what you want to do

Note.
see the drawing of the car as it is made.
points to degree 0 (zero)
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
or do you want to do this:

@oparra... You are right.. I required whatever you post at #10..

Also How do I point the custom marker to degree 0 (zero) .?
Below is the code snippet for marker for change of position of marker...
B4X:
Sub Update_Driver(newloc as Location)
 If newloc.IsInitialized Then
Dim CameraPosition1 As CameraPosition 'CameraPosition1.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, 0, 0)
CameraPosition1.Initialize(newloc.Latitude,newloc.Longitude, 20)
Dim newLatLong As LatLng
newLatLong.Initialize(newloc.Latitude,newloc.Longitude)
gmap.moveCamera(CameraPosition1)
mrkr(vhlMarkerId).Position=newLatLong
mrkr(vhlMarkerId).Draggable=True
Dim   mx As MarkerExtras
mx.SetRotation(mrkr(vhlMarkerId),newloc.BearingTo(lastLocation))
lastLocation=newloc
End If
End Sub


Please advice
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…