user2466886
user2466886

Reputation: 205

Displaying phone's geo location on screen with ionic

I'm learning ionic and I'm having trouble displaying my Android phone's geo location (lat and long) on screen. How can I do this?

Code take from https://www.tutorialspoint.com/ionic/ionic_geolocation.htm

.controller('GeoCtrl', function($scope, $cordovaGeolocation) {
   $scope.result = "";
   var posOptions = {timeout: 10000, enableHighAccuracy: false};
   $cordovaGeolocation
   .getCurrentPosition(posOptions)

   .then(function (position) {
      var lat  = position.coords.latitude;
      //$scope.geo.lat = position.coords.latitude;
      var long = position.coords.longitude;
      //$scope.geo.long = position.coords.longitude;
      console.log(lat + '   ' + long)
      $scope.geo = lat + '   ' + long;
   }, function(err) {
      console.log(err)
   });

})

And here's the html where i just want the geo location to be displayed:

<ion-view view-title="Submit New Thing">
  <ion-content class="padding">
  <h2>List of items for sale</h2>
     <div >
     <h3> Geo locaton is {{geo}}</h3> 
      </div>
   </ion-content>
</ion-view>

When I test on my phone {{geo}} is literally displayed.

Upvotes: 1

Views: 71

Answers (1)

user2466886
user2466886

Reputation: 205

Answer: I didn't have the ngCordova dependency injected into the app.

Upvotes: 1

Related Questions