Table view data object to sqlite db
I have a tableview made up from data that is held in a data object:
var data = [
// BEDFORDSHIRE
{title:BushmeadPrioryParams.title, hasChild:true, test:BushmeadPrioryParams, header:'Bedfordshire'},
{title:DeGreyMausoleumParams.title, hasChild:true, test:DeGreyMausoleumParams},
{title:dunstabledownsParams.title, hasChild:true, test:dunstabledownsParams},
{title:HoughtonHouseParams.title, hasChild:true, test:HoughtonHouseParams},
etc.
in turn this data is held in an additional js file that looks like:
var dunstabledownsParams = {
latitude:51.859700,longitude:-0.546390,
title:"Dunstable Downs",
subtitle:'Bedfordshire',
animate:true,
rightButton: Titanium.UI.iPhone.SystemButton.DISCLOSURE,
window: win3,
latitudeDelta:0.04, longitudeDelta:0.04
};
var dunstabledowns = Titanium.Map.createAnnotation(dunstabledownsParams);
Ideally I need a way of filtering this data by distance from the users current location, say 20miles? There doesnt seem to be any information that I can find on how this can be done, or indeed if it can be achieved.
Alternatively is there a way to easily port this information into a sqlite database? As I have seen an good example of distance filtering using a sql query string.
Thank you in advance for your help!
1 Answer
-
Rather than putting all the locations into the data array, you can dynamically add rows to the table. You'd read the data from your js file and determine the distance from the user to that location. If within the range, add the row to the table. You have the lat/long of all the points and the same data for the user.
See http://www.movable-type.co.uk/scripts/latlong.html or http://www.zipcodeworld.com/samples/distance.js.txt for Javascript versions of the math. According to this page, http://www.gsak.net/help/hs23810.htm there is a built-in sqlite function to do this, too. The Google API includes a function, but I don't think it would be accessible within your app.