javascript - AngularJS - orderBy distance function -


I'm very innovative for AngularJS, so be easy on me ... :-) In the process of building a building New PhoneGap App with Ionic Framework and AngularJS I have a list of those places which have an output and a function in the list view that will look at the user's location and will get the distance between their current location and the location in the list . These are currently both works properly and I can see my list, sorted by normal areas (name, etc.).

What I would like to do is a preference screen where the user has already set up my preferred Sorting Options I have already set up my basic priority controller, which is currently only storing priority for sorting by 'name' But I want to sort it down by the distance, which is done by the below-seen function. But since the distance function is seen in this controller, I do not know how to make it?

Again, I'm new so any help would be greatly appreciated!

Here's my controller:

  .controller ('LocationsCtrl', function ($ radius, $ ionic loading, $ ionic popups, location service, settings) {$ Scope.locations = {}; $ scope.navTitle = "Location list"; $ radius .rightButtons = [{type: 'button-icon button-clear ion-plus', tap: function (e) {$ Call scope.openSortModal ();}}}; // Call on the infinite scroll, callback / to receive an "made" infinite scroll, to inform that we $ scope.loadMore = function () {$ timeout (function () {// placeholder $ $ later. $ Pras RANGING ('scroll.infiniteScrollComplete')}}, 1000) are showing; $ Scope.loading = $ ionic Loading. ({Content: 'Getting current location ...', shown backdrop: incorrect} ); Navigator.Golocation.GetContotCoices (Function (Pause) {varCoos = $ scope.orrent location = [paused calls lame, pos.coords.latitude]; $ Scope.locations = LocationsService.allSync (); $ Scope .sortLoc = SettingsService.get ('sortLocBy'); $ IonicLoading.hide ();}, function (error) {$ ionicPopup.alert ({title: 'Unable to get location:' error. Message)} then (function) {$ ionicLoading.hide (); // is not working}); }); $ Scope.distanceFromHere = function (_item, _startPoint) {var start = null; Var radian to = function (start, end) {var d2r = Math.PI / 180.0; Var lat1rad = start.latitude * d2r; Var long1rad = start.longitude * d2r; Var lat2rad = end.latitude * d2r; Var long2rad = end.longitude * d2r; Var deltaLat = lat1rad - lat2rad; Var Delta Long = Long 1 Rad - Lambdaad; Var sinDeltaLatDiv2 = Math. sin (deltaLat / 2); Var sinDeltaLongDiv2 = Math. sin (Delta Long / 2); // Straight line between the two points, square half of the distance of the square distance var a = ((sinDeltaLatDiv2 * sinDeltaLatDiv2) + (Math.cos (lat1rad) * math kos (lat2rad * sinDeltaLongDiv2 * sinDeltaLongDiv2)); A = Math.Man (1.0, A); Return 2 * math.Syn (math.Sqrt (A)); }; If ($ scope.currentLocation) {start = {longitude: $ scope.current location [0], Latitude: $ scope.current location [1]}; } Start = _startPoint || Start; Var end = {longitude: _item.location.lng, latitude: _item.location.lat}; Var num = radiansTo (start, end) * 3958.8; Return Mathematics field (number * 100) / 100; }}  

And here's my template:

  & lt; Ion-view title = "{{navTitle}}" left-button = "left button" & gt; & Lt; Ion-content header-scroll scroll-event-interval = "5" & gt; & Lt; Ion-list class = "place-list" & gt; & Lt; Ion-item class = "space-item" ng-repeat = "location in place | orderbank: sortlok" type = "item-text-wrap" href = "# / location / {{loc.id}} / description" style = "Background-image: url ('{{loc.photos.0.url}}');" & gt; & Lt; Div class = "location-title" & gt; & Lt; P & gt; {{Loc.name}} & lt; / P & gt; & Lt; Span class = "distance-pointer" & gt; & Lt; Span class = "points" & gt; {{DistanceFromHere (loc)}} & lt; / Span & gt; & Lt; Span class = "unit" & gt; Miles & lt; / Span & gt; & Lt; / Span & gt; & Lt; / Div & gt; & Lt; / Ion item & gt; & Lt; / Ion list & gt; & Lt; / Ion content & gt; & Lt; / Ion-view & gt;  

As the orderbyy expression, you can use a function that generates a value to use for sorting. All you need to do is to enter the distanceFromHere function in your sortable squash variable (or by filtering the order: distance form ).


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -