|
define(function(require){
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
var Baas = justep.Baas;
var CommonUtils = require("$UI/system/components/justep/common/utils");
var bmap = require('$UI/system/components/justep/bmap/bmap');
require("$UI/system/lib/cordova/cordova");
require("cordova!cordova-plugin-device");
require("cordova!com.justep.cordova.plugin.weixin.v3");
require("cordova!com.justep.cordova.plugin.alipay");
require("cordova!cn.jpush.phonegap.JPushPlugin");
require("cordova!com.justep.cordova.plugin.unionpay");
require("res!./img");
require("cordova!cordova-plugin-geolocation");
require("cordova!com.justep.cordova.plugin.baidulocation");
var Model = function() {
/*this.callParent();
this.arr = [];*/
this.callParent();
this._deviceType = "pc"; // pc || wx || app
this._userID = "user";
this._userDefaultName = "新用户";
this._userDefaultAddress = "";
this._userPhotoURL = "";
};
Model.prototype.locationClick = function(event) {
var me =this;
//this.wxApi = new navigator.WxApi("wx799221c9cb7cd688");
if (this.wxApi) {
this.wxApi.exec().done(function(wx) {
wx.getLocation({
type : "gcj02",
success : function(data) {
wx.openLocation({
latitude : data.latitude,
longitude : data.longitude,
name : '',
address : '当前位置',
scale : 14,
infoUrl : 'http://wex5.com'
})
},
cancel : function(res) {
}
});
}).fail(function() {
});
} else {
function successCallback(position){
//debugger;
justep.Util.hint(position.address);
me.comp("windowDialog1").open({
data : {
latitude : position.coords.latitude,
longitude : position.coords.longitude
}
});
alert("地址" + position.address +"坐标系" + position.coorType+ "纬度" + position.coords.latitude+"经度" + position.coords.logitude);
/*alert("地址" + position.address);
alert("坐标系" + position.coorType);
alert("纬度" + position.coords.latitude);
alert("经度" + position.coords.logitude);*/
//me.comp("windowDialog1").open({data:JSON.stringify(position)});
}
function errorCallback(position){
alert("失败");
}
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
}
};
Model.prototype.getLocation = function() {
var gpsDtd = $.Deferred();
if (this.wxApi) {
this.wxApi.exec().done(function(wx) {
wx.getLocation({
type : "gcj02",
success : function(data) {
gpsDtd.resolve({
coorType : data.coorType,
address : data.address,
longitude : data.longitude,
latitude : data.latitude
});
},
cancel : function(res) {
gpsDtd.resolve({
longitude : 116.45764191999997,
latitude : 39.8622934399999
});
}
});
}).fail(function() {
gpsDtd.resolve({
longitude : 116.45764191999997,
latitude : 39.8622934399999
});
});
} else if (navigator.geolocation) {
var success = function(data) {
// data.longtitude 经度
// data.latitude 纬度
// data.address 文字描述的地址信息
// data.hasRadius 是否有定位精度半径
// data.radius 定位精度半径
// data.type 定位方式
// data.coorType
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 : 116.45764191999997,
latitude : 39.8622934399999
});
};
/**
* 如果在室内 enableHighAccuracy: true 反而误差更大
* 如果在室外 enableHighAccuracy: true 相对准确
*/
navigator.geolocation.getCurrentPosition(success, fail);
/*var gpsWatchID = navigator.geolocation.watchPosition(success, fail,{
timeout: 30*1000,
maximumAge: 30000,
enableHighAccuracy: true});*/
} else {
justep.Util.hint("获取地理位置失败,暂时采用默认地址");
gpsDtd.resolve({
longitude : 116.45764191999997,
latitude : 39.8622934399999
});
}
return gpsDtd.promise();
};
return Model;
});
|
-
报错信息
|