我在 angular 中使用 ngMap 进行谷歌地图集成。
下面是我的html代码
<map ng-transclude class='google-map' center="map.center">
<marker position="marker.position" options="marker.options"></marker>
</map>
我的 Controller 代码是
//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
}
}
};
};
在这种情况下, map 已显示,但 map 中心显示不正确,它位于右侧。
如果我将下面的代码放在带有虚拟纬度和经度的函数外部,那么它工作正常,但我无法在该函数外部获得动态经纬度值,这就是我需要将此代码放入函数中的原因。
$scope.map = {
center: [18.9750, 72.8258]
};
请帮我解决问题。
最佳答案
你可以看看
center="{{map.center}}"
并在 $timeout
函数中设置您的数据。如果你的纬度,经度完美,可能是 Angular 摘要问题
$timeout(function() {
$scope.map = {
center: [latitude, longitude]
};
});
关于javascript - ngMap 中心在 angularjs 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35200196/