Note that there are some explanatory texts on larger screens.

plurals
  1. POsencha touch sort list by Distance
    primarykey
    data
    text
    <p>i want to sort a list of Locations by its Distance(displayed in list). i already have a code that sould work but since i am that new to the whole mvc thing, i am not really sure where to place it to make it work.</p> <p>Maybe someone can help me:</p> <pre><code> 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 &amp;&amp; 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(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload