How Do You Make Map Rotate With User?

How can I make the map component rotate such that the top of the map is the user's bearing direction (like Google Maps does in navigating)? I have the idea to subtract the latitudes and logitudes from the user's current location and the user's location 2 seconds ago, and based on the polarity of the results, I can rotate it by 90° increments. Obviously this won't cover every possible orientation, so is there some way to identify the user's orientation?

Using the Map component check EnableRotation
mapOrientation

This only enables manual rotation of the map, I want to somehow programmatically find which direction the user is facing and rotate the map accordingly.

Oops, failed to attach this rough code. Adjust it as to how often you want to update :wink:

You can try this and adapt.
rotatemap

assuming you have an Orientation sensor.

Perhaps add the Map Compass, a scale etc. to make it pretty.

This gives me strange results.

I applied the code, however when the compass shows north, the map shows north, but I am actually facing Northwest. When the compass shows South, the map shows Southeast and my device is actually facing West-southwest.

However, perhaps its my orientation sensor?

works for me. Perhaps you have something like a large metal desk (like I do) or an electric motor or a magnet nearby in your testing location. Walk outside and test? :slightly_smiling_face:

or you might need this

Ah, yes; more stable. But now both with and without the modulo block, if I rotate from N to W, it goes from N to E. If I rotate S to E, it goes S to W. Essentially, if I do a full rotation clockwise, it spins counterclockwise.

perhaps the timer cannot keep up with fast device orientation changes? I don't know. I have not observed what you note in my experiments. Experiment with the TimerInterval? Perhaps rapid orientation changes is the issue.

I slowed and sped up the clock, and it's still reversing direction.

However is there any way to map an integer where 0 becomes 360 and 360 becomes 0? I've done this with Arduino but I don't know how to do it in MIT App Inventor.

modulo should take care of that

for what it is worth
azimuth or perhaps

azimuth2

Azimuth : 0 degree when the top of the device is pointing north, 90 degrees when it is pointing east, 180 degrees when it is pointing south, 270 degrees when it is pointing west, etc

1 Like

Ohh, I see; I'll try some other things later. Thanks for your help!

Finally, after trying so many different things, this is what worked:

Turns out the inputs of this block needed reversed.

EDIT I have asked AI how to do this and this is what it gave me:


As far as I know it works, but I have something wrong in my code. I'll post an update if I get it to work

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.