|
楼主 |
发表于 2019-6-25 15:02:58
|
显示全部楼层
- define(function(require){
- var $ = require("jquery");
- var justep = require("$UI/system/lib/justep");
-
- require("cordova!cordova-plugin-geolocation");
-
- var Model = function(){
- this.callParent();
- };
- Model.prototype.modelLoad = function(event){
- var self = this;
- var onDeviceReady = function(){
- self.getPosition();
- };
-
- document.addEventListener("deviceready", onDeviceReady, false);
- };
- Model.prototype.getPosition = function(){
- navigator.geolocation.getCurrentPosition(success, fail, null);
- function success(){
- var coo = data.coords;
- console.log(coo);
- }
-
- function fail(error){
- switch (error.code) {
- case error.PERMISSION_DENIED:
- console.log("User denied the request for Geolocation.");
- alert("用户不允许地理定位!");
- break;
- case error.POSITION_UNAVAILABLE:
- console.log("Location information is unavailable.");
- alert("位置信息不可用!");
- break;
- case error.TIMEOUT:
- console.log("The request to get user location timed out.");
- alert("获取用户位置的请求超时!");
- break;
- case error.UNKNOWN_ERROR:
- console.log("An unknown error occurred.");
- alert("发生了一个未知错误!");
- break;
- }
- }
- };
-
- return Model;
- });
复制代码 在生成的调试模式app中,打开页面,没有弹框提示 用户进行位置信息的授权。 |
-
|