Is this possible? Depending on exactly what you expect to happen, it might not be practical. Explain more about what you have done so far and what you expect to happen.
To show when a bus deviates from it's route it would be through comparing points on the route with the bus' actual location. The LocationSensor has no tools within its self to do this.
Here are some possible things you could try:
Using the LocationSensor alone.
Rather than noting whether at any point in time the bus deviates from its route, try to determine whether the bus is following its path. Periodically check whether the bus is with the boundaries of the path. If the bus is not within the path boundaries, you know it has deviated and can use a Texting tool to send an sms message to the phone or to make the phone play a sound.
How?
1) Create a series of 'ring fences' that describe the bus route. If the route follows a rectangular grid of streets, setting up the 'ring fences' would be easy. If the bus moves obliquely to the street grid,using orthogonal ring fences to display the route becomes complex and probably impractical (you would have to create a series of small ring fences that mimic diagonal movement).
2 ) Using the device's GPS and the LocationSensor, check to see whether the bus is within any of the series of 'ring fences' at a specific time interval. A simple way to set up a ring fence using coordinates is described here
Chapter 18. Programming Your App to Make Decisions3) If the bus is within its path 'boundaries', all is well so do nothing.
4) If the bus is not within the path, make a noise or send an sms
Using the LocationSensor plus the MIT Map component.
You might be able to Create a series of FeatureCollections or perhaps LinesStrings or Polygons representing the route.
The Map component has tools to determine how far away the device is from each of these objects.
Map components
How?
1) Create a FeatureCollection, a series of LineStrings or a Polygon that describes the bus route.
2) MIT Map has a tool to determine how far the device is away from each of these.
3) A Polygon is a special case that might be used to determine if the device is within the boundaries of the polygon. The device is within the polygon, it is on the route. If it is not, the bus has gone on an excursion.
There are lots of things that make an app like this difficult; among these is the ability of a particular Android device (cell or tablet) to know exactly where it is within any precision. This limits your ability to determine small excursions. Generally, most devices know where they are within about 30 meters or less (but if you understand how a LocationSensor works, the precision can be improved)
Using the Location Sensor
Sorry, you cannot use App Inventor to create a self driving bus.
So, are you still interested? Even attempting such a project requires a lot of App Inventor and GIS skills. Whether something can be programmed to determine if a bus is on its established route depends on the complexity of the bus route, what you expect, your ability to create your own bus trak (using LineStrings perhaps) or a polygon.
A way to create a polygon of the bus route is to use an online free tool like
geojson.io . The tools allows you to make a complicated polygon and save its geojson description as a text file. In the image below, the bus 'route' is the fuchsia colored line, the polygon created with the polygon tool is the grey area. The tool generates a geojson polygon. The geojson displays on the right side of the image. Use the online tool's
Save to save as a geojson file to your computer. Upload the geojson to your MIT Map component Polygon.
![busroute.PNG](https://groups.google.com/group/mitappinventortest/attach/22662b75d32cc/busroute.PNG?part=0.1&view=1)
Determine if the bus (with the Android) is within or outside of the Polygon generated using code similar to these Blocks:
![busRoute2.PNG](https://groups.google.com/group/mitappinventortest/attach/22662b75d32cc/busRoute2.PNG?part=0.2&view=1)
( I coded them from my memory.) Try it and see if it works for you. (the width of the polygon needs to be reasonably wide..I expect 20 meters wide either side of the route centerline might work with most GPS receivers). If the above code does not work, you probably only need to change the centroid Block value to false. Check the route with the above code in a Button or a Clock event handler. If the bus is behaving, the Boolean areOnTheRoute variable should be true
Good luck. Let us know how it goes.
Regards,
Steve