model view controller - sencha touch sort list by Distance -
i want sort list of locations distance(displayed in list). have code sould work since new whole mvc thing, not sure place create work.
maybe can help me:
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(){ homecoming * 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 = 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 homecoming 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 set geocode on 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 not done or can not 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 location.'); }else{ ext.msg.alert('error getting location. please create sure location services enabled on device.'); } list.setmask(false); } } } }); geo.updatelocation();
i found solution.just adding listener navigation/list view should it. had much in controller decided set straight view.
list model-view-controller sorting sencha-touch distance
No comments:
Post a Comment