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).

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.