我想通过 Google map v3 获得与 Pinterest map (例如 www.pinterest.com/airbnb/loved-by-parisians/)相同的效果。
到目前为止我已经做到了:http://jsfiddle.net/tdff3/9xEEG/
我缺少一件事: 移动中心 map 位置并将标记可见区域更改为右侧,以响应不同的分辨率。
现在:
我想要的:
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 张图片上并不相同。
如果你在整个澳大利亚都有标记,那么边界看起来就像你的第二张照片中的那样。如果不是,但您仍然想要实现此特定 View ,那么您可能需要调整缩放级别以确保它以这种方式显示,或者手动定义这些边界。
关于 map 向右移动,可以用 map panBy() method这允许您按给定的像素距离更改 map 的中心。
希望这对您有所帮助!
关于javascript - 谷歌地图 v3 像 Pinterest map (移动中心位置和改变标记区域),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453329/