これは、バックエンド サービスからオブジェクトを取得するための get メソッドです。
// LocationService add, update, delete, etc
.service('LocationService', function ($http, Backand) {
// Initiation the opject
var baseUrl = '/1/objects/';
var objectName = 'location/';
var query ='/1/query/data/';
function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}
function getUrlForId(id) {
return getUrl() + id;
}
getLocations = function (id) {
var url = Backand.getApiUrl() + query + 'getLocationbyUserName?' + 'parameters=%7B%22Username%22:%22habibi%22%7D';
//var url = 'https://api.backand.com/1/query/data/getLocationbyUserName?parameters=%7B%22Username%22:%22ha%22%7D';
//var url = getUrlForId(id);
return $http.get(url);
};
コントローラーを追加
LocationService.getLocations('2').then(function (result) {
$scope.location = result.data;
alert($scope.location.latitude);
friendLatitude = $scope.location.latitude;
friendLongtitude = $scope.location.longtitude;
},function(error){
console.log("LocationService cannot get friend location");
});
ただし、 $scope.location.latitude is undefined から結果を得ました