繁体   English   中英

像Pinterest Map一样的Google Maps v3(移动中心位置并更改标记区域)

[英]Google Maps v3 like Pinterest Map (move center position and change markers area)

我想在Google Maps v3中获得与Pinterest Map(例如www.pinterest.com/airbnb/loved-by-parisians/)相同的效果。

到目前为止,我已经来到这里: http : //jsfiddle.net/tdff3/9xEEG/

我缺少一件事:移动中心地图位置并在右侧更改标记的可见区域,以响应不同的分辨率。

现在:

我想要的是:

function initialize()
{
    var mapOptions =
    {
        zoom: 8,
        center: new google.maps.LatLng( -33.9, 151.2 ),
        disableDefaultUI: true,
        zoomControl: true,
        zoomControlOptions:
        {
            style: google.maps.ZoomControlStyle.SMALL,
            position: google.maps.ControlPosition.RIGHT_BOTTOM
        },
        scrollwheel: false
    };

    var map = new google.maps.Map
    (
        document.getElementById( 'map-canvas' ),
        mapOptions
    );

    var beaches =
    [
        [ 'Bondi Beach', -33.890542, 151.274856, 4 ],
        [ 'Coogee Beach', -33.423036, 151.259052, 5 ],
        [ 'Cronulla Beach', -34.028249, 121.157507, 3 ],
        [ 'Manly Beach', -33.80010128657071, 151.28747820854187, 2 ],
        [ 'Maroubra Beach', -33.450198, 151.259302, 1 ]
    ];

    setMarkers( map, beaches );
}

function setMarkers( map, locations )
{
    var bounds = new google.maps.LatLngBounds();

    for( var i = 0; i < locations.length; i++ )
    {
        var beach = locations[ i ];
        var myLatLng = new google.maps.LatLng( beach[ 1 ], beach[ 2 ] );
        var marker = new google.maps.Marker(
        {
            position: myLatLng,
            map: map,
            title: beach[ 0 ],
            zIndex: beach[ 3 ]
        } );

        bounds.extend( myLatLng );
    }

    map.fitBounds( bounds );
}

function loadScript()
{
    var script = document.createElement( 'script' );
    script.type = 'text/javascript';
    script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' +
        'callback=initialize';
    document.body.appendChild( script );
}

window.onload = loadScript;

我认为这将是所有标记的扩展范围的标记区域在您发布的2张图片上并不相同。

如果您在澳大利亚各地都有标记,那么边界看起来就像第二张图片。 如果不是,但是您仍想获得此特定视图,则可能需要使用缩放级别以确保以这种方式显示,或手动定义这些范围。

关于向右移动地图,您可以使用地图panBy()方法 ,该方法可让您将地图中心更改为给定距离(以像素为单位)。

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM