2016-02-04 24 views
2

正常工作,我在角爲谷歌地圖整合使用ngMap。ngMap中心沒有在angularjs

下面

是我的HTML代碼

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

我的控制器的代碼是

//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 
     } 
     } 
    }; 

}; 

在這種情況下,地圖顯示,但地圖中心顯示不正確,它會到達右側。

如果我把下面的代碼以外的功能與虛擬lat和長那麼它的工作正常,但我不能這個功能,這就是爲什麼我需要把這個代碼功能之外得到動態的緯度和長期價值。

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

請幫我解決。

回答

1

您可以檢查它

center="{{map.center}}" 

$timeout功能設置您的數據。可能是角度,如果你的緯度消化問題,東經完美

$timeout(function() { 
    $scope.map = { 
     center: [latitude, longitude] 
    }; 
}); 
+0

我試圖與中心= 「map.center」 以及中心= 「{{map.center}}」,但不適合我 –

+0

工作檢查你的'response.latitude'和'response.longitude'值 –

+0

是我檢查一切都很好。當我使用虛擬數據將scope.map函數聲明在函數外面時,它的範圍有問題,然後它正在工作。 –

0

實際上要覆蓋我們$scope.map

請更新

function mapCenter(latitude, longitude) { 

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

還可以使用dorebuildall="true" propeprty