How to display Nearest Locations in Corona?

Hello,

I’m planning to create an app about missing children in the US. I’d like to create a feature that lists the children nearest to the user’s current location. This is based on the child’s original hometown or the place where the child was last seen. What is the easiest way to do this in Corona?

Below is an image of my UI design to give a better idea of what I’m trying to do.
 

question_image_zpsde3360e7.png

Also, how can the children’s age listings be updated automatically?

Any help would be really appreciated. Thanks.

Corona sdk provides api for obtaining geolocalisation of device based on internet or gps connection. If you have some server you can send coordinates there and find localisations of missings near this point. Or if you have list of coordinates then you can store it in local database.

If you need automatic updates of listing then you should have server with database or at least some file online. Then you can always pull data down to device.

I agree with piotrz55,

I’m working on something similar that stores objects in parse.  Once I have the device’s GPS I perform a $nearShere query (https://www.parse.com/docs/rest#geo) and use $maxDistanceInMiles to filter.   Look into mod_parse by develephant (http://www.develephant.net/). 

I’m also working on a module using mapbox to generate markerclusters - like this: https://www.mapbox.com/mapbox.js/example/v1.0.0/markercluster-with-mapbox-data/

A lot depends on your source of data.  Lets talk about the age first.  If you have a birth day, then you would calculate the age.  You would use the various os.date() and os.time() functions and a little math to figure out the age.  If you do this, you won’t have to update the age in your data, it will simply draw the right age.

As for the distance, you would have your data in a table with the Lat, Long of the person and use the GPS to get the Lat, Long of where you are.  Then with some simple trig you can get the distance between the two points.  Store that distance in your records for each person then use table.sort() to sort the data before you insert it into your tableView.

Much thanks everyone for your responses. I’ll see if I can get it to work. 

@Pjoli:

Is this what you’re looking for? 

http://forums.coronalabs.com/topic/37827-calculate-distance-between-points-sort-them-works/

Can both of these methods be done without a database? I’m fairly new to mobile app development.

Thanks for the link! I won’t be starting the app for a few more weeks but I’ll see if it works.

Hello again. Can both of these methods be done without a database? I’ll have to start building the app in the next few days.

You have to have some data.  It doesn’t need to be in a formal database.

Rob

Thanks for the response!

Of course but db was suggested because you could sort data using database queries. However you can always load some saved data and sort it yourself :slight_smile:

 

I tried using os.time and os.date to subtract the birth year from the current year. Below is the code I used.

 

print(os.time{year=1998, month=6, day=24, hour=0, sec=0}) --898660800 print(os.date("%G") - os.date("%G", 898660800) )

However, I notice that this doesn’t take into consideration the month and day of the birthday, thus giving an inaccurate age. For example, if someone turns 16 on June 24, 2014 , the age would already show as ‘16’ as soon as new year comes. It doesn’t wait until June 24 of that year. 

Does anyone know how I could get the age to change on the exact birthdate? Thanks.

Corona sdk provides api for obtaining geolocalisation of device based on internet or gps connection. If you have some server you can send coordinates there and find localisations of missings near this point. Or if you have list of coordinates then you can store it in local database.

If you need automatic updates of listing then you should have server with database or at least some file online. Then you can always pull data down to device.

I agree with piotrz55,

I’m working on something similar that stores objects in parse.  Once I have the device’s GPS I perform a $nearShere query (https://www.parse.com/docs/rest#geo) and use $maxDistanceInMiles to filter.   Look into mod_parse by develephant (http://www.develephant.net/). 

I’m also working on a module using mapbox to generate markerclusters - like this: https://www.mapbox.com/mapbox.js/example/v1.0.0/markercluster-with-mapbox-data/

A lot depends on your source of data.  Lets talk about the age first.  If you have a birth day, then you would calculate the age.  You would use the various os.date() and os.time() functions and a little math to figure out the age.  If you do this, you won’t have to update the age in your data, it will simply draw the right age.

As for the distance, you would have your data in a table with the Lat, Long of the person and use the GPS to get the Lat, Long of where you are.  Then with some simple trig you can get the distance between the two points.  Store that distance in your records for each person then use table.sort() to sort the data before you insert it into your tableView.

Much thanks everyone for your responses. I’ll see if I can get it to work. 

@Pjoli:

Is this what you’re looking for? 

http://forums.coronalabs.com/topic/37827-calculate-distance-between-points-sort-them-works/

Can both of these methods be done without a database? I’m fairly new to mobile app development.

Thanks for the link! I won’t be starting the app for a few more weeks but I’ll see if it works.