|
我用下面的方法实现手机定位,打包安卓apk的时候,安装手机定位没问题,
但是打包ios后,手机定位就失败
require("cordova!cordova-plugin-geolocation");
// 查询地址
Model.prototype.queryAddr = function() {
var self= this;
var gpsDtd = this.getLocation(); // 获取当前信息
gpsDtd.done(function(position) {
self.latitude = position.latitude; // 纬度
self.longitude = position.longitude; // 经度
alert(position.latitude);
});
};
// 获取当前位置
Model.prototype.getLocation = function() {
var gpsDtd = $.Deferred();
if (navigator.geolocation) {
var success = function(data) {
gpsDtd.resolve({
coorType : data.coorType,
address : data.address,
longitude : data.coords.longitude,
latitude : data.coords.latitude
// 文字描述的地址信息
});
};
var fail = function(e) {
justep.Util.hint("获取地理位置失败,暂时采用默认地址");
gpsDtd.resolve({
longitude : 115.633617,
latitude : 29.063769
});
};
navigator.geolocation.getCurrentPosition(success, fail);
} else {
justep.Util.hint("获取地理位置失败,暂时采用默认地址");
gpsDtd.resolve({
longitude : 115.633617,
latitude : 29.063769
});
}
return gpsDtd.promise();
};
|
|