【问题标题】:The `bounds` parameter in `angular-google-map` not working?`angular-google-map`中的`bounds`参数不起作用?
【发布时间】:2015-01-20 10:18:52
【问题描述】:

看到这个DEMO

document中看到bounds参数的描述是:

在指定的范围内调整地图。表达式必须解析为 具有东北和西南属性的物体。其中每一个 属性必须有一个纬度和一个经度属性

我在范围内设置了界限:

$scope.bd = {
  northeast: {
    latitude: 51.219053,
    longitude: 4.404418
  },
  southwest: {
    latitude: -51.219053,
    longitude: -4.404418
  }
}

并在这样的指令中使用它:

<ui-gmap-google-map bounds="bd" center="map.center" zoom="map.zoom" draggable="true" options="options"></ui-gmap-google-map>

但似乎没有效果..地图不适合我指定的边界..这是否意味着边界参数不起作用?以及如何使地图适合指定的边界?

【问题讨论】:

    标签: google-maps-api-3 angular-ui angular-google-maps


    【解决方案1】:

    为什么不使用中心和缩放而不是边界?

    无论如何,我正在做一些测试,因为中心、缩放和边界都在指令内,它们是异步加载的,并且由于需要中心和缩放,边界不会受到影响。

    即使设置值没有改变(不知道为什么)

    http://plnkr.co/edit/YdyYIiVVgApA2tpm11Xn?p=preview

    setTimeout(function(){
      var map = $scope.instance.getGMap();
      console.log(map);
      console.log(map.getBounds());
    
    
    
    $scope.bd = {
      northeast: {
        latitude: 51.219053,
        longitude: 4.404418
      },
      southwest: {
        latitude: -51.219053,
        longitude: -4.404418
      }
    }
    
                        ne = new google.maps.LatLng($scope.bd.northeast.latitude, $scope.bd.northeast.longitude);
                sw = new google.maps.LatLng($scope.bd.southwest.latitude, $scope.bd.southwest.longitude);
                bounds = new google.maps.LatLngBounds(sw, ne);
    map.fitBounds(bounds);
    
    
    
    }, 2000);
    

    【讨论】:

    • 我动态计算我的界限,所以所有标记都完美地显示在视图中。仅使用中心和缩放是不可能的。
    猜你喜欢
    • 2016-12-05
    • 2014-10-30
    • 2018-01-06
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    相关资源
    最近更新 更多