使用离子显示屏幕上的手机地理位置

时间:2016-11-06 15:08:00

标签: android angularjs ionic-framework

我正在学习离子,而我在屏幕上显示Android手机的地理位置(纬度和长度)时遇到问题。我怎么能这样做?

代码来自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)
   });

})

这里是html,我只想显示地理位置:

<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>

当我在手机上测试{{geo}}时,字面显示。

1 个答案:

答案 0 :(得分:1)

答案:我没有将ngCordova依赖注入到应用程序中。

相关问题