 <p>1) create a javascript <code>restaurant</code> class</p> <p>2) give the restaurant class a <code>distanceFrom(lat, long)</code> function</p> <p>3) adapt your factory to return <code>restaurant</code>s rather than <code>object</code>s</p> <p>4) sort list of <code>restaurant</code>s by the <code>distanceFrom</code> function</p> <pre><code>function Restaurant(name, lat, long) { this.name = name; this.lat = lat; this.long = long; this.distanceFrom = function(long_from, lat_from) { return calculateDistanceBetween(this.lat, this.long, lat_from, long_from); } } </code></pre> <p>usage:</p> <pre><code>var myPosition = { lat: 50.0123, long: 49.4321 }; var someRestaurant = new Restaurant('The food', 51.1231, 48.213312); var howFar = someRestaurant.distanceFrom(myPostion.lat, myPosition.long); </code></pre> <p>for a javascript sample of getting distance between two latitude/ logitude pairs, see here: <a href="http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points">How do I calculate distance between two latitude-longitude points?</a></p>