Skip to first unread message

klvio...@gmail.com

unread,
Jul 8, 2014, 10:16:50 PM7/8/14
to mitappinv...@googlegroups.com
Hello All
A group of students is interested in setting a radius for GPS.  They would like to create an app that will adjust the ringer settings based on location.  Looking for suggestions on how to do this.. Can a radius be set using the location sensor?  
Thanks
Kristin

SteveJG

unread,
Jul 9, 2014, 7:28:43 AM7/9/14
to
By radius, I assume you mean a set distance the device is from the Android devices's current location to someother location?

1.  You have to know the distance between the two locations. and the RADIUS you want to test for.

1a.  Save the someother location to compare with the Android's currrent location .  The student's can use the Where's My Car tutortial as an example of how to store the otherlocation and use it ...http://explore.appinventor.mit.edu/ai2/tutorials?field_tutorial_type_tid%5B%5D=91&field_tutorial_type_tid%5B%5D=67

2)  Calculate distance D,  either by using simple trig, the Haversine formula.  Both are useful for short straight-line distances.   It is also possible to 'determine distance separation in other ways.    If the student's are advanced, they can use aspects of the Google Map API to do this.  There also is an example in the free online book here         http://www.appinventor.org/book2   in the section on Sensors              that demonstrates how the distance can be calculated based on small changes in latitude or longitude, however be careful, this is not a set distance but varies depending on latitude and deviation of the devices latitude.

3.  Use the locationsensor to determine the Android's current location.  (See the LocationSensor tutorial here     http://explore.appinventor.mit.edu/ai2/tutorials?field_tutorial_type_tid%5B%5D=91&field_tutorial_type_tid%5B%5D=67           to understand what this sophisticated control can do.

4.   Then use an if statement with a Clock timer to continuously check the distance between the two locations.    Set the Clock to the interval you want to check...remember the time interval is in ms     You should not perhaps refresh faster than one minute, the timer defaults at one second unless you change the setting.....    if distance  > RADIUS then     do this, if distance <= RADIUS do that     Be aware, the location may take 10 to 20 seconds to get a satellite fix.  Sometime the fix is withing 4 or 5 seconds.   Why is this important?     You do not want to check the distance over small time intervals.  The sensor normally checks the position once every 60 seconds...unless the programmer tells it to do something else with their software (Interval).

..That should get them started.

If they are adventurous, they might look at the concept discussed in the LocatonSensor tutorial called Distance, they might be able to use that for RADIUS somehow, however, be aware of two things,   Distance units are in meters and it should be used in conjunction with the concept of Accuracy ...If they are successful, be sure and return and celebrate and let others know how they did it....

Regards,
Steve
Reply all
Reply to author
Forward
0 new messages