How do you add a distance to a GPS coordinates.

4,076 views
Skip to first unread message
Assigned to steve....@gmail.com by me

itce...@gmail.com

unread,
Feb 13, 2014, 4:43:14 AM2/13/14
to mitappinv...@googlegroups.com
How do you add a distance to a GPS coordinates.

How to, if I have a coordinate
43.162055, -95.856578 and will add 100 meters in one or more directions

SteveJG

unread,
Feb 13, 2014, 5:54:07 PM2/13/14
to
The distance between each degree of latitude varies.  The distance variation is from 110.567 km at the Equator to 111.699 km at the poles.  On average the distance between degree latitude lines is about 111 km apart.  The exact amount is a difficult calculation because of the earth's ellipsoid shape and is specific to any one location.


The distance between each degree of longitude varies greatly depending on location.  Each degree of longitude is widest at the Equator (111.321 km ) and gradually decreases to 0 at the poles.  At 40 degrees north or south of the Equator, the distance between a degree of longitude is about  85 km.

If you read different texts, you will discover the values calculated/recommended as average may be slightly different values than presented here.

So, for 43.162055 degrees of latitude and -95.856578 degrees of longitude  you could assume latitude degrees is 85 km apart and about 50 km approximately for longitude (because you are slightly  less than halfway to the North pole).

This link tells you how to be more specific (be aware, the calculation is in English units, not metric):  http://www.colorado.edu/geography/gcraft/warmup/aquifer/html/distance.html

This link:  http://www.movable-type.co.uk/scripts/latlong.html     provides a robust formula to calculate the distance from any location to another location, such as someone might want if they were writing a geochaching app.  You have to make your own blocks and in your case, if you actually need 100m, will have execute the algorithm in reverse.  This algorithm is good for short distances.  If you need to calculate distances between continents, us Vincenties' algorithm http://www.movable-type.co.uk/scripts/latlong-vincenty.html  (that is going to be a lot of blocks).

Is this what you are looking for?



Best luck,
Steve

SteveJG

unread,
Feb 14, 2014, 11:01:58 AM2/14/14
to mitappinv...@googlegroups.com, itce...@gmail.com

Jeg leste litt Norsk, om det hjelper. Dette er ikke vanskelig. Jeg tror jeg misforsto spørsmålet ditt.

What exactly are you trying to do with the locations in your app? Calculating the distance between two different locations is not very difficult, it just requires using a lot of the math blocks.  Determining if a point lays on a circle with a radius of 100m is more difficult but it it is doable with AI2.

I am glad to help you figure out what you need if you tell me more.

Asbjorn, please respond in the forum if possible rather than by direct email.  Taks skal du ha.

-- Steve

itce...@gmail.com

unread,
Feb 15, 2014, 7:40:04 AM2/15/14
to mitappinv...@googlegroups.com, itce...@gmail.com
I hope that this respons in forum

I want to get an alert if I am not moving.
Since GPS can be jumping back and forth, I will sit an area around my point that will trigger the alarm.

So I need to read a coordinate, and then add and subtract, I saw a box that I need to move out within a variable time, otherwise you have to get an alarm.

Asbjørn.
Not Norway, but Danish ;)

SteveJG

unread,
Feb 15, 2014, 8:42:34 AM2/15/14
to mitappinv...@googlegroups.com, itce...@gmail.com
Dansk, ikke norsk.   Very good, you Danes were always more tolerant of my Norwegian pronunciation.than the Norwegians :)

Yes, this is possible and quite easy.  What you need is  a "set  LocationSensor1.DistanceInterval to .. 100    blocks., The measurement is not precise using this method.  If you can live with some imprecision; it is the way to go. This is an explaination:
"Determines the minimum distance interval, in meters, that the sensor will try to use for sending out location updates. For example, if this is set to 5, then the sensor will fire a LocationChanged event only after 5 meters have been traversed. However, the sensor does not guarantee that an update will be received at exactly the distance interval. It may take more than 5 meters to fire an event, for instance."

A second way is to save a start location and continually compare the present location with the original location.  You would calculate the distance between the start location and the location now on a continuous basis and when the distance is greater than 100 meters, your app would tell you.

I will send you some blocks for the first method later today.   I have some blocks for the math required in the second method in a large app.  I will see if I can put those blocks in an example also.  There are a lot of blocks in the calculation and doing the example might take me a week or so.  I have other projects. :(.

At the end of this note is a list of the things you can do easily with the Location Sensor.

Regards,
Steve

LocationSensor

This component provides the Android device's location, using GPS if available and an alternative method otherwise, such as cellular towers or known wireless networks.

LocationSensor is a non-visible component providing location information, including longitude, latitude, altitude (if supported by the device), and address. This component can also provide geocoding, converting a given address (not necessarily the current one) to a latitude (with the LatitudeFromAddress method) and a longitude (with the LongitudeFromAddress method).

In order to function, the component must have its Enabled property set to true, and the device must have location sensing enabled through either GPS satellites (if the device is outdoors) or an alternative method.

Properties

Accuracy
Indicates Android device accuracy level, in meters.
Altitude
Altitude of the Android device, if available.
AvailableProviders
List of available service providers, such as gps or network
CurrentAddress
Physical street address of the Android device.
DistanceInterval
Determines the minimum distance interval, in meters, that the sensor will try to use for sending out location updates. For example, if this is set to 5, then the sensor will fire a LocationChanged event only after 5 meters have been traversed. However, the sensor does not guarantee that an update will be received at exactly the distance interval. It may take more than 5 meters to fire an event, for instance.
Enabled
If set, location information is available.
HasAccuracy
If true, Android device can report its accuracy level.
HasAltitude
If true, Android device can report its altitude.
HasLongitudeLatitude
If true, Android device can report longitude and latitude.
Latitude
Android device latitude.
Longitude
Android device longitude.
ProviderLocked
The device will not change the service provider.
ProviderName
The current service provider.
TimeInterval
Determines the minimum time interval, in milliseconds, that the sensor will try to use for sending out location updates. However, location updates will only be received when the location of the phone actually changes, and use of the specified time interval is not guaranteed. For example, if 1000 is used as the time interval, location updates will never be fired sooner than 1000ms, but they may be fired anytime after.

Events

LocationChanged(number latitude, number longitude, number altitude)
Called when the Android device reports a new location.
StatusChanged(text provider, text status)
Called when the status of the service provider changes.

Methods

number LatitudeFromAddress(text locationName)
Determines the latitude of the given address.
number LongitudeFromAddress(text locationName)
Determines the longitude of the given address.

SteveJG

unread,
Feb 15, 2014, 11:29:43 AM2/15/14
to mitappinv...@googlegroups.com, itce...@gmail.com
Attached is an app that attempts to demonstrate  a few capabilities of an AI2 Location sensor.  If things are not working as you expect, please leave a comment. If you find a better way of doing something, please let me and others know by posting here.

Things developers need to consider when using the Location sensor in AI2:

1) The sensitivity of the receivers of the gps in different devices varies.  Some devices are more sensitive to whether the phone/tablet is in a building, under trees or is traveling in canyon like environments (i.e. in the mountains, between sky scrapers or merely tall buildings).

2) A gps receiver's accuracy is dependent on the number of satellites  it can get a fix on (receive) at any moment.  Consequently, accuracy of location reported by the device can vary easily by plus or minus 50 meters or so.  Accuracy is also dependent on the quality of the gps in your device.  Real gps devices, not tablets/phones, can be accurate to within less than a meter.  Your phone is no where near that capability.

3) My experience with the gps in a Galaxy Tab 2 7" tablet is the LocationSensor DistanceInterval when set to 100 can 
trigger a change of location response, even when the tablet is at rest, not often, but it happens.  A 100 m setting is reasonable but does not guarantee 100 meters of separation.

4) When the GPS accuracy is reported, for instance 32 meters, it means that a LocationSensor DistanceInterval set to anything less than 32 meters, the gps will change as if the distance is set to 0.   The gps units in phones especially are not very precise.

5) To get an idea of how your device's accuracy changes, set the distance to zero and monitor the line that shows changes in accuracy of your GPS in the app.


6) The demo app I developed this morning also collects data from your device.  Not all phones/tablets provide all this data.  Many phones may not have the altitude data, for instance.


7) I am not sure if the data provided to the device GPS is persistent or not, therefor there is a "Close the app and reset Location Distance to 0" button, which should be the GPS's default status.

8) Be sure to read the MIT App Inventor's team description of the sensor here:  http://appinventor.mit.edu/explore/content/sensors.html

9) 60000 ms is one minute.

Things to do:   a) make it look pretty, b) add a vibrate or sound alarm, c) check that it really works for you.

Have fun exploring the Location sensor,
-- Steve

LocationSensor_09.aia
Message has been deleted

itce...@gmail.com

unread,
Feb 17, 2014, 6:41:20 AM2/17/14
to mitappinv...@googlegroups.com, itce...@gmail.com
Thank you, it was something like that I was looking for.
So now I can move on, but it will probably take some time, since I just are in learning about app programming.
Reply all
Reply to author
Forward
0 new messages