Results 1 to 5 of 5
  1.    #1  
    Hi All,

    I'm working on my first app for webOS, being a public transport tool for the public transport from the GVB company in Amsterdam, The Netherlands, which will give you the nearest public transport stop, schedule and real time departure info. Similar to Bus Tracker.

    I want to bring some new free apps specifically for the Dutch market, since webOS is really undervalued here currently and I'd like to change this by extending the number of available apps

    I'm getting quite far already, however I'm having a problem sorting my JSON array by the distance to the stop. I was able to get my current GPS coordinates, calculate the distance to the stop, add a distance in the JSON array, but now I'm stuck on how to sort this JSON array based on distance. Any help would be highly appreciated. I've been trying different things, but without success, even good old Google doesn't seem to be of too much help....

    Original JSON:

    {
    "TIMINGPOINT": {
    "000012": {
    "DataOwnerCode": "ALGEMEEN",
    "LocationX_EW": "124052",
    "LocationX_WGS84": "4.932872",
    "LocationY_NS": "486034",
    "LocationY_WGS84": "52.361325",
    "TimingPointCode": "000012",
    "TimingPointName": "Muiderpoortstation",
    "TimingPointTown": "Amsterdam"
    },
    "000051": {
    "DataOwnerCode": "ALGEMEEN",
    "LocationX_EW": "124047",
    "LocationX_WGS84": "4.932800",
    "LocationY_NS": "486022",
    "LocationY_WGS84": "52.361217",
    "TimingPointCode": "000051",
    "TimingPointName": "Muiderpoortstation",
    "TimingPointTown": "Amsterdam"
    },
    "000052": {
    "DataOwnerCode": "ALGEMEEN",
    "LocationX_EW": "124047",
    "LocationX_WGS84": "4.932800",
    "LocationY_NS": "486022",
    "LocationY_WGS84": "52.361217",
    "TimingPointCode": "000052",
    "TimingPointName": "Muiderpoortstation",
    "TimingPointTown": "Amsterdam"
    }
    }
    }
    JSON with Distance added:

    {
    "TIMINGPOINT": {
    "000012": {
    "DataOwnerCode": "ALGEMEEN",
    "LocationX_EW": "124052",
    "LocationX_WGS84": "4.932872",
    "LocationY_NS": "486034",
    "LocationY_WGS84": "52.361325",
    "TimingPointCode": "000012",
    "TimingPointName": "Muiderpoortstation",
    "TimingPointTown": "Amsterdam",
    "Distance": "145"
    },
    "000051": {
    "DataOwnerCode": "ALGEMEEN",
    "LocationX_EW": "124047",
    "LocationX_WGS84": "4.932800",
    "LocationY_NS": "486022",
    "LocationY_WGS84": "52.361217",
    "TimingPointCode": "000051",
    "TimingPointName": "Muiderpoortstation",
    "TimingPointTown": "Amsterdam",
    "Distance": "234"
    },
    "000052": {
    "DataOwnerCode": "ALGEMEEN",
    "LocationX_EW": "124047",
    "LocationX_WGS84": "4.932800",
    "LocationY_NS": "486022",
    "LocationY_WGS84": "52.361217",
    "TimingPointCode": "000052",
    "TimingPointName": "Muiderpoortstation",
    "TimingPointTown": "Amsterdam",
    "Distance": "345"
    }
    }
    }
    Thanks in advance
  2. #2  
    Quote Originally Posted by Herrie View Post
    Hi All,

    I'm working on my first app for webOS, being a public transport tool for the public transport from the GVB company in Amsterdam, The Netherlands, which will give you the nearest public transport stop, schedule and real time departure info. Similar to Bus Tracker.

    I want to bring some new free apps specifically for the Dutch market, since webOS is really undervalued here currently and I'd like to change this by extending the number of available apps

    I'm getting quite far already, however I'm having a problem sorting my JSON array by the distance to the stop. I was able to get my current GPS coordinates, calculate the distance to the stop, add a distance in the JSON array, but now I'm stuck on how to sort this JSON array based on distance. Any help would be highly appreciated. I've been trying different things, but without success, even good old Google doesn't seem to be of too much help....

    Original JSON:



    JSON with Distance added:



    Thanks in advance
    Not sure there is a way to sort properties on an object -- like JSON objects. I would push each one into an array, then define a sort function based upon the distance property of the array item.

    ex:
    Array = [];

    function sortFunction(a, b){
    return (a.Distance - b.Distance)
    }

    for(var item in Obj){
    if(Obj.hasOwnProperty(item)){
    Array.push(Obj[item]);
    }
    }

    Array.sort(sortFunction);
    French Pre3, UK Pre2, US Veer, German gsm Pre, 680, garmin ique 3600 & still have my working palm pilot 1000 with the 1 Mb adapter

    Please remove UberCalendar and google sync behavior patches prior to system updates.
    patch Google calendar sync behavior for 2.x.x and TouchPad (Oauth2 and advanced sync requirements enabled)
    Preference guide for MetaView's UberCalendar patch
  3. #3  
    Given what you're doing, instead of using a simple JSON structure, include an array in that structure to hold each location, so you can sort it directly rather than have to create an array just for sorting. That is, assuming you control the structure.
    Last edited by Grabber5.0; 04/30/2012 at 09:14 AM.
  4.    #4  
    Thanks for the feedback.

    I had the JSON into an array already, but just didn't get my head around getting it sorted properly. I now pushed the items into a new array, removing the Timingpoint level, so my array is very straight forward now.

    myarray[i][distance]
    myarray[i][stopname]

    etc

    This one I could sort easily

    Now working out additional info for the app
  5.    #5  
    OK, now I'm stuck again on another bit. I was able to pull all the stops, calculate the distance sort it etc. Now I want to add the bus/metro/tram lines to the station name. However in order to get the lines I need to do another Ajax request and will get a JSON back.

    How can I update my array that I already created with the JSON results that I got back?

    I managed to do the Ajax request, call the Success function, select all the lines, remove the duplicates, sort them by line number and put them into a single string, however I cannot seem to figure out how to push it back into the array that I already have?

Posting Permissions