我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