我Service.js类型错误:无法读取属性 '然后' 未定义
appnService.factory('LocationService', function(){
var currentLocation = {
latitude:"",
longitude:""
}
return {
GetLocation : function(){
return navigator.geolocation.getCurrentPosition(function(pos){
currentLocation.latitude = pos.coords.latitude;
currentLocation.longitude= pos.coords.longitude;
return currentLocation;
});
}
};
});
我控制器
appne.controller('NewObservationCtrl',function($scope,$state,LocationService) {
LocationService.GetLocation().then(function(data){
console.log(data);
});
});
但即时得到错误
类型错误:无法读取属性 '然后'在控制器中未定义
请帮忙
也许是因为[navigator.geolocation.getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/ getCurrentPosition)无返回 – Hacketo
CurrentLocation的值为{对象:纬度:11.9384867,经度:79.8352657} –
看起来那段代码'return navigator.geolocation.getCurrentPosition' – Hacketo