【问题标题】:Location alert on iosios上的位置提醒
【发布时间】:2015-09-23 13:35:51
【问题描述】:

我在 iOS 上使用 ionic 创建的应用存在问题。 在我的主菜单中,当我按下一个按钮时,我的应用程序会尝试获取我的位置并显示两个警报: 一份意大利语(没错)和一份英文:

ITA:

英语:

第二个警报太难看了。我希望警报是:“MYAPP vuole usare la tua posizione”。如何更改第二个警报的文本?

【问题讨论】:

  • 能否提供一些代码、您使用的库以及您的 Cordova Location 插件的版本?

标签: javascript ios geolocation ionic


【解决方案1】:

您可能需要将您的 Cordova 位置请求包装在控制器中的 ionicPlatform.ready

.controller("MapController", ["$scope", "$cordovaGeolocation", "$ionicPlatform", function($scope, $cordovaGeolocation, $ionicPlatform) {

      $ionicPlatform.ready( function() {

            $cordovaGeolocation
              .getCurrentPosition()
              .then(function (position) {
                // do something
                }
              }, function(err) {
                // error
              });

      })

}])

【讨论】:

    【解决方案2】:

    您需要知道 Javascript 警报和原生警报之间的区别。

    您可能可以使用cordova notification 插件并在其中显示所需的输出。

    您可以从这里获取插件信息: https://cordova.apache.org/docs/en/3.0.0/cordova_notification_notification.md.html

    并从 github repo 下载插件

    代码实现如下:

    $cordovaGeolocation
                  .getCurrentPosition()
                  .then(function (position) {
                    //here call the notify method
                    navigator.notification.alert(message, alertCallback, [title], [buttonName]) // instead of message pass the position 
                    //title it so index.html will not be displaying
                    }
                  }, function(err) {
                    // error
                  });
    

    【讨论】:

      【解决方案3】:

      如果您担心外观,可以尝试使用自定义提醒,如甜蜜提醒。 http://t4t5.github.io/sweetalert/

      JS:

      var script_0 = document.createElement('script');
      script_0.src = "https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js";
      document.body.appendChild( script_0 );
      
      
      var link_0 = document.createElement('link');
      link_0.rel = "stylesheet";
      link_0.type = "text/css";
      link_0.href = "https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css";
      document.body.appendChild( link_0 );
      

      或 HTML:

      <script src="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js">     </script>
      <link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-28
        相关资源
        最近更新 更多