Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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!

— asked September 19th 2010 by Ian Tearle
  • data
  • sqlite
  • tablview
0 Comments

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.

    — answered September 19th 2010 by Tim Poulsen
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.