首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用angular- Google -maps设置google Maps边界

使用angular- Google -maps设置google Maps边界
EN

Stack Overflow用户
提问于 2015-04-07 03:29:18
回答 2查看 10.1K关注 0票数 5

我正在尝试设置Google Maps实例的界限,但没有成功。我使用的是AngularJS和angular-google-maps模块。我的最后一次尝试是:

代码语言:javascript
复制
<div id="map_canvas">
    <ui-gmap-google-map 
        center="map.center" 
        zoom="map.zoom"
        bounds="map.bounds"
        options="options">

        <div ng-repeat="d in devicesMarkers track by d.id">

            <ui-gmap-marker
                idkey="d.id"
                coords="d.center"
                options="d.options">
            </ui-gmap-marker>
            <ui-gmap-circle
                center="d.center"
                stroke="d.circle.stroke"
                fill="d.circle.fill"
                radius="d.circle.radius"
                visible="d.options.visible">
            </ui-gmap-circle>

        </div>

    </ui-gmap-google-map>
</div>

在我的app.js中,我写道:

代码语言:javascript
复制
(...)
.controller('TaihMapController', ['$scope', '$log', 'uiGmapGoogleMapApi', function($scope, $log, GoogleMapApi) {
    $scope.devicesMarkers = devices;
    $scope.map = {
        center: { latitude: devices[0].center.latitude, longitude: devices[0].center.longitude },
        zoom: 12,
        bounds: {}
        // fit: true,
    };
    GoogleMapApi.then(function(maps) {
        $log.debug(maps);
        var myBounds = new maps.LatLngBounds();
        for (var k = 0; k < devices.length; k++) {
            var _tmp_position = new maps.LatLng(
                devices[k].center.latitude, 
                devices[k].center.longitude);
            myBounds.extend(_tmp_position);
        }
    $scope.map.bounds = myBounds;
    $scope.googleVersion = maps.version;
    // $scope.bounds = myBounds;
    // $scope.zoom = maps.getZoom();
    // maps.fitBounds(myBounds);
    // $scope.bounds = maps.getBounds();

});

函数maps.fitBounds()不存在。我尝试了$scope.map.bounds方法,但没有按照我认为的方式进行响应。

EN

回答 2

Stack Overflow用户

发布于 2016-03-16 20:01:43

如果您正在使用angular-google-map的"markers“指令,只需添加fit="true”属性(ui-gmap-markers)。

示例:

<ui-gmap-google-map center="map.center" zoom="map.zoom" options="map.options"> <ui-gmap-markers fit="true" models="markers" coords="'self'"></ui-gmap-markers> </ui-gmap-google-map>

来源:https://stackoverflow.com/a/29707965

票数 9
EN

Stack Overflow用户

发布于 2015-09-11 16:57:38

根据docs的说法,指令边界与谷歌地图边界略有不同。您应该使用northeastsouthwest属性自己的latitudelongitude显式设置它们。

下面的代码应该可以:

代码语言:javascript
复制
$scope.map.bounds = {
    northeast: {
        latitude: myBounds.getNorthEast().lat(),
        longitude: myBounds.getNorthEast().lng()
    },
    southwest: {
        latitude: myBounds.getSouthWest().lat(),
        longitude: myBounds.getSouthWest().lng()
    }
};
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29478220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档