3

I am using ngMap in angular for google map integration.

below are my html code

<map ng-transclude class='google-map' center="map.center"> 
    <marker position="marker.position" options="marker.options"></marker>
</map>

my controller code is

//response get from server side 
var onResponse = function(response){
    $scope.workshop = response;
    mapCenter(response.latitude, response.longitude);

};

function mapCenter(latitude, longitude) {

    $scope.map = {
      center: [latitude, longitude]
    };

    $scope.marker = {
      position: [latitude, longitude],
      options: function(){
        return {
          draggable: true
        }
      }
    };

};

In this case map is display but center of map is not display properly it gets to the right side.

If I put below code outside function with dummy lat and long then it's working fine but I can't get dynamic lat and long value outside this function that's why I need to put this code in function.

$scope.map = {
          center: [18.9750, 72.8258]
        };

Please help me for solution.

Dipak Dendage
  • 628
  • 1
  • 6
  • 25

2 Answers2

1

you can check it

center="{{map.center}}"

and set your data in $timeout function. may be angular digest problem if your latitude, longitude perfect

$timeout(function() {
    $scope.map = {
      center: [latitude, longitude]
    };
});
Shaishab Roy
  • 16,335
  • 7
  • 50
  • 68
0

actually you are overwriting our $scope.map.

Please update

function mapCenter(latitude, longitude) {

                $scope.map.center =[latitude, longitude];
                $scope.marker.position = [latitude, longitude];
            };

Also use dorebuildall="true" propeprty

RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53