简体   繁体   中英

Location alert on ios

I have a problem with my app on iOS created using ionic. In my home menu, when I press a button, my app tries to get my location and it shows me two alerts: one in Italian(that's right) and one in english:

ITA:

意大利警报

ENGLISH:

英文警报

The second alert is so ugly. I would like that the alert will be: "MYAPP vuole usare la tua posizione". How can I change the text of the second alert?

You will probably need to wrap your Cordova location request inside an ionicPlatform.ready in your controller

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

      $ionicPlatform.ready( function() {

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

      })

}])

You need to know there are difference between Javascript alert and native alerts.

You could probably use cordova notification plugin and show the desire output inside it.

You could get plugin information from here: https://cordova.apache.org/docs/en/3.0.0/cordova_notification_notification.md.html

and download the plugin from github repo

Code implementation would be like:

$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
              });

If you're worried about the looks you could try using a custom alert like sweet alert. 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 );

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM