Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

Code review and update list in real time

$
0
0

@a_mohamed80 wrote:

Hi all
I am trying to create prototype "prove of concept" for my team member.I created app to track position of user when they click "get my start location" and start watching position after user click getEndTrackingLocation() it will store end position and update div list of location.position.coords in view. I want to ask is my logic is correct way to track location a. and how can view list in realtime ?

view
<ion-view title="GPSLogging" ng-controller="GpsLoggingCtrl as vm">
<ion-content class="has-header padding">
<button class="button button-full button-balanced" ng-click="vm.getInitLocation()">get my start location</button>
<button class="button button-full button-balanced" ng-click="vm.getStartTrackingLocation()">get my start location</button>
<button class="button button-full button-balanced" ng-click="vm.getEndTrackingLocation()">get my end location</button>
<div class="list">
<div ng-repeat="location in vm.geoLocations">
<div class="item item-divider item-energized">{{location.position.coords.latitude }},{{location.position.coords.longitude }}</div>
</div>
</ion-content>
</ion-view>

controller

(function () {
'use strict';

angular.module('ngApp').controller('GpsLoggingCtrl', ['$cordovaGeolocation', GpsLoggingCtrl]);

function GpsLoggingCtrl($cordovaGeolocation) {
    var vm = this;


  var posOptions = {timeout: 10000, enableHighAccuracy: true};
  vm.getInitLocation = function () {
    $cordovaGeolocation
      .getCurrentPosition(posOptions)
      .then(function (position) {
    alert('Latitude: '          + position.coords.latitude          + '\n' +
        'Longitude: '         + position.coords.longitude         + '\n' +
        'Altitude: '          + position.coords.altitude          + '\n' +
        'Accuracy: '          + position.coords.accuracy          + '\n' +
        'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
        'Heading: '           + position.coords.heading           + '\n' +
        'Speed: '             + position.coords.speed             + '\n' +
        'Timestamp: '         + position.timestamp                + '\n'
        );

      }, function(err) {
          alert('code: '    + err.code    + '\n' +
            'message: ' + err.message + '\n');
      });
  };

  vm.getEndLocation = function(){

  };


  var watchOptions = {
    enableHighAccuracy: false, // may cause errors if true,
    frequency:1000
  };

  var watch = $cordovaGeolocation.watchPosition(watchOptions);
  var geoLocation = [];



  vm.getStartTrackingLocation = function () {
    watch.then(
        null,
        function(err) {
        alert('code: '    + err.code    + '\n' +
                'message: ' + err.message + '\n');
        },
        function(position) {

        geoLocation.push(position)
        });
  };

  vm.getEndTrackingLocation = function(){
      watch.then(
        null,
        function(err) {
        alert('code: '    + err.code    + '\n' +
                'message: ' + err.message + '\n');
        },
        function(position) {

        geoLocation.push(position)
        });
        vm.geoLocations = geoLocation;
  };

 watch.clearWatch();
};

})();
[/quote]

controller

(function () {
'use strict';

angular.module('ngApp').controller('GpsLoggingCtrl', ['$cordovaGeolocation', GpsLoggingCtrl]);

function GpsLoggingCtrl($cordovaGeolocation) {
    var vm = this;


  var posOptions = {timeout: 10000, enableHighAccuracy: true};
  vm.getInitLocation = function () {
    $cordovaGeolocation
      .getCurrentPosition(posOptions)
      .then(function (position) {
    alert('Latitude: '          + position.coords.latitude          + '\n' +
        'Longitude: '         + position.coords.longitude         + '\n' +
        'Altitude: '          + position.coords.altitude          + '\n' +
        'Accuracy: '          + position.coords.accuracy          + '\n' +
        'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
        'Heading: '           + position.coords.heading           + '\n' +
        'Speed: '             + position.coords.speed             + '\n' +
        'Timestamp: '         + position.timestamp                + '\n'
        );

      }, function(err) {
          alert('code: '    + err.code    + '\n' +
            'message: ' + err.message + '\n');
      });
  };

  vm.getEndLocation = function(){

  };


  var watchOptions = {
    enableHighAccuracy: false, // may cause errors if true,
    frequency:1000
  };

  var watch = $cordovaGeolocation.watchPosition(watchOptions);
  var geoLocation = [];



  vm.getStartTrackingLocation = function () {
    watch.then(
        null,
        function(err) {
        alert('code: '    + err.code    + '\n' +
                'message: ' + err.message + '\n');
        },
        function(position) {

        geoLocation.push(position)
        });
  };

  vm.getEndTrackingLocation = function(){
      watch.then(
        null,
        function(err) {
        alert('code: '    + err.code    + '\n' +
                'message: ' + err.message + '\n');
        },
        function(position) {

        geoLocation.push(position)
        });
        vm.geoLocations = geoLocation;
  };

 watch.clearWatch();
};

})();

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>