android - 使用 ionic 在屏幕上显示手机的地理位置

标签 android angularjs ionic-framework

我正在学习 ionic,但在屏幕上显示我的 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}} 字面上显示。

最佳答案

回答:我没有在应用程序中注入(inject) ngCordova 依赖项。

关于android - 使用 ionic 在屏幕上显示手机的地理位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40450843/

相关文章:

javascript - 在 AngularJS 中仅接受字母数字和 1 点

angularjs - Google NoCaptcha ReCaptcha 仅在 Angular SPA 中刷新时显示

android - 启动应用程序后在 Android Studio 中 Hook

android - Firebase 中的 Facebook 身份验证不起作用

android: 无法运行程序 CreateProcess error=5,访问被拒绝

java - 如何从 ActivityGroup 调用 ActivityGroup 的子 Activity 中的非静态方法?

javascript - Angularjs - ng-route 在 IE9 上不工作 - 不显示 View

javascript - Cordova插件错误: Resource interpreted as Script but transferred with MIME type text/plain

reactjs - Stencil 与 React 和 Angular 有何不同?

typescript - 如何在Ionic4 Angular中使用电容器保存下载的文件?