【问题标题】:sencha touch sort list by Distancesencha touch 按距离排序列表
【发布时间】:2013-02-18 08:09:46
【问题描述】:

我想按距离对位置列表进行排序(显示在列表中)。 我已经有一个可以工作的代码,但是由于我对整个 mvc 东西还很陌生,所以我不确定将它放在哪里才能使它工作。

也许有人可以帮助我:

 var geocoder = new google.maps.Geocoder();
 var geo = Ext.create('Ext.util.Geolocation',{
autoUpdate: false,
listeners: {
    locationupdate:{
        scope: this,
        fn: function(geo){
            var haversindeDistance = function(lat1,lon1,lat2,lon2){
                if(typeof(Number.prototype.toRad)=="undefined"){
                        Number.prototype.toRad = function(){
                            return this * Math.PI/180;
                        }
                }
                var R = 6371; //km
                var dLat = (lat2-lat1).toRad();
                var dLon = (lon2-lon1).toRad();
                var lat1 = lat1.toRad();
                var lat2 = lat2.toRad();

                var a = Math.sin(dLat/2)*Math.sin(dLat/2)+
                        Math.sin(dLong/2)*Math.sin(dLon/2)*Math.cos(lat1)*Math.cos(lat2);
                var c = 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));
                var d = R*c;
                // KM or MIles
                //return d*0.621371192; //MIles
                return d;
            };
        var store = Ext.getStore('locationsstore');
        store.suspendEvents(true);
        store.each(function(location){
            var lat2 = parseFloat(location.get(geocoder.geocode( { 'address': sAddress}, function(results, status) { })))||0;
            var lon2 = parseFloat(location.get(geocoder.geocode( { 'address': sAddress}, function(results, status) { })))||0;
            //var lat2 = parseFloat(location.get('lat'))||0;//try to put geocode on this ish
            //var lon2 = parseFloat(location.get('lon'))||0;
            if(lat2 && lon2){
                var distance = haversineDistance(geo.getLatitude(),geo.getLongitude(),lat2,lon2);
                location.set('distance',distance);
            }
        }, this);
        store.resumeEvents();
        store.filter('distance',/\d/);
        store.sort('distance');//check if it is not done or can not be done somewhere else
        list.setMasked(false);
    }
},
    locationerror:{
        scope: this,
        fn:function(geo,bTimeout,bPermissionDenied,bLocationUnavailable,message){
        console.log([geo,bTimeout,bPermissionDenied,bLocationUnavailable,message]);
        if(bTimeout){
            Ext.Msg.alert('Timed out getting your location.');
        }else{
            Ext.Msg.alert('Error getting location. Please make sure location services are enabled on your Device.');
        }
        list.setMask(false);
        }
    }
    }
 });
 geo.updateLocation();

【问题讨论】:

    标签: list model-view-controller sorting sencha-touch distance


    【解决方案1】:

    我找到了解决方案。只需将侦听器添加到导航/列表视图即可。我在 Controller 里的东西太多了,所以我决定直接把它放到 View 中。

    【讨论】:

    • 你能告诉我们你添加了什么监听器吗?对于正在寻找类似内容的其他人可能会有所帮助
    • 我将整个代码放在控制器中。通过将其放置/移动到列表视图来解决问题,我希望将其排序为:painted: function(){ ^^code
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    相关资源
    最近更新 更多