0

I am making a location based application using phonegap, first I get all the data from the web wich is a json format, and then I store all the data into json array objects, Then I sort the array objects according to the distance, however I want to load like 12 items each time after sorting the json array but have no idea how to approach it.

I know I could use limit 0, 12 in mysql when I send request to the web but I would not able to sort all the data beacause I can only sort 12 data retrieved from the web each time, is there a way to load 12 items each time after all the data has been sorted, the whole purpose is just to increase the speed, I don't want to load all the data from the web sort all of them and append all of them in the listview.

Can Anyone give me some idea, any help will be appreciated. Apologize for not giving any code, because I haven't code them yet.

here is the code I have cracked on

$.ajax({
    url: 'http://www.example.com/getdata.php? &format=json',
    dataType: 'json',
    success: function (d) {
        var items = d.posts;
        $.each(items, function (key, val) {
            var d = getDistanceFromLatLonInKm(localStorage.current_latitude, localStorage.current_longtitude, parseFloat(val.post.latitude), parseFloat(val.post.longtitude));
            jsonObj.push({
                title: val.post.title,
                distance: d,
                description: val.post.description
            });
        });
        jsonObj.sort(function (a, b) {
            return parseFloat(a.distance) - parseFloat(b.distance)
        });
        $.each(jsonObj, function (index, data) {
            $("#results").append("<li>" + data.title + data.description + data.distance + "</li>");
        }
        });
4

1 回答 1

0

将位置与您的请求一起发送,在 MySQL 中对数据进行排序,然后返回任意数量的数据。

于 2013-06-01T04:51:00.480 回答