0

I am using Nicolas Laplante google-maps (http://nlaplante.github.io/angular-google-maps/) module. I have problem when passing coordinates for center property from asynchronous call:

This is my controller:

app.controller('baznaCtrl',function($scope,$routeParams,$http){
    $scope.idB=$routeParams;
    $scope.latitude=0;
    $scope.longitude=0;
    $http.get('https://my web service/json/'+$scope.idB.lokid).success(function(data){
        $scope.bs=data;
        $scope.latitude=$scope.bs.lattitude.replace(',','.');
        $scope.longitude=$scope.bs.longitude.replace(',','.');
    }); 

    angular.extend($scope,{
        center : {
            latitude: $scope.latitude,
            longitude:$scope.longitude
        },
        markers:[],
        zoom: 8
    });     
});

It seems that google-map does not changing it's center property when data comes from $http call. It is always 0,0 (because of initial values of $scope.latitude and $scope.longitude).

pbaris
  • 4,525
  • 5
  • 37
  • 61
Tomislav
  • 3,181
  • 17
  • 20

1 Answers1

1

Please use promises in angular js to make the ajax calls work perfectly.

Refer these examples:

What is the best practice for making an AJAX call in Angular.js?

http://markdalgleish.com/2013/06/using-promises-in-angularjs-views/

Community
  • 1
  • 1
webcoder
  • 656
  • 6
  • 12
  • So you suggest that I have to put $http call in the factory and then use data from it as promise for google map center property? – Tomislav Oct 18 '13 at 08:59