i'm doing mobile app using angularjs. i'm trying achieve update geolocation data turn on gps. how achieve this? problem i'm facing is, in order data updated have navigate other page. these codes. i'm sharing data 1 controller other.
.factory('sharedproperties', function () { var coordinates = {}; var getc = function () { return coordinates; }; var setc = function (value) { coordinates = value; return coordinates; }; return { getcoords: getc, setcoords: setc }; })
first controller
.controller('messagecontroller', ['$scope', 'sharedproperties', function ($scope, sharedproperties) { var nobj = sharedproperties.getcoords(); console.log(nobj); $scope.message = "this location: " + nobj.lat + ", " + nobj.lng + ". i'm around " + nobj.acc + " meters point."; }])
second controller
.controller("maincontroller", ['$scope', 'sharedproperties', function ($scope, sharedproperties) { $scope.lat = "0"; $scope.lng = "0"; $scope.accuracy = "0"; $scope.error = ""; $scope.model = { mymap: undefined }; $scope.mymarkers = []; $scope.showresult = function () { return $scope.error == ""; } $scope.mapoptions = { center: new google.maps.latlng($scope.lat, $scope.lng), zoom: 15, maptypeid: google.maps.maptypeid.roadmap, disabledefaultui: true }; $scope.showposition = function (position) { $scope.lat = position.coords.latitude; $scope.lng = position.coords.longitude; $scope.accuracy = position.coords.accuracy; $scope.$apply(); sharedproperties.setcoords({ 'lat': position.coords.latitude, 'lng': position.coords.longitude, 'acc': position.coords.accuracy }); var latlng = new google.maps.latlng($scope.lat, $scope.lng); $scope.model.mymap.setcenter(latlng); $scope.mymarkers.push(new google.maps.marker({ map: $scope.model.mymap, position: latlng, title: 'you here' })); } $scope.showmarkerinfo = function (marker) { $scope.myinfowindow.open($scope.model.mymap, marker); }; $scope.showerror = function (error) { switch (error.code) { case error.permission_denied: $scope.error = "user denied request geolocation." break; case error.position_unavailable: $scope.error = "location information unavailable." break; case error.timeout: $scope.error = "the request user location timed out." break; case error.unknown_error: $scope.error = "an unknown error occurred." break; } $scope.$apply(); } $scope.getlocation = function () { if (navigator.geolocation) { navigator.geolocation.getcurrentposition($scope.showposition, $scope.showerror, { enablehighaccuracy: true}); } else { $scope.error = "geolocation not supported browser."; } } $scope.getlocation(); }])
edit:
somehow managed work this.
.controller('messagecontroller', ['$scope', 'sharedproperties', function ($scope, sharedproperties) { $scope.getloc = function () { var nobj = sharedproperties.getcoords(); console.log(nobj); var numbers = [nobj.lat, nobj.lng, nobj.acc]; return "this location: " + numbers[0].tofixed(6) + ", " + numbers[1].tofixed(6) + ". i'm around " + numbers[2].tofixed(0) + " meters point."; }])
and in view, put this.
<textarea style="width: 100%; height: 183px;" placeholder="message">{{getloc()}}</textarea>
but displays {{getloc()}} in textarea. there anyway can hide , show when gets data?
you may use ng-bind-html
so
<textarea style="width: 100%; height: 183px;" placeholder="message" ng-bind-html="getloc()"></textarea>
Comments
Post a Comment