You use the LocationSensor in AI. The orientation and accelerometer can not provide the information you need.
If the distance is not large:
- Rough Distance
sqrt( (69.1 * (lat2Degrees-lat1Degrees))^2 + (53.0 * (lon2Degrees-lon1Degrees))^2 )
You really should not be concerned with much accuracy if you are planning on using this function as you’ll easily get 10% or more distance errors. The basic idea is to take the average distance per degree longitude and latitude and use it to convert degrees to distance. If you are using miles you’d use 69.1 miles for each degree latitude and 53.0 miles for each degree longitude. 53.0 miles is an average and you can adjust this to closer match the actual distance for a degree longitude at a given latitude. But if you do that you might as well use the previous function since it is exactly doing that.You can use this formula if any of these conditions apply:
– very short distances.
– if you’re data is limited to a local area and you can use an adjusted distance for one degree longitude.
– if 10% or more inaccuracy is sufficient for your needs.
– for comparison of distances
This distance is in miles, you need to convert to meters/kilometers using the Math blocks.
If the distance is larger ... Google haversine formula
Both methods provide straight - line distance between two know points.
There are other ways to do this. What you do depends on what your app must do.
Regards,
Steve