マップの境界を設定しようとしています fitbounds は機能しません。境界の周りにスペースを配置するためです。
{{{map.fitBounds(map.getBounds())}}}
数回すると、マップがすばやくズームアウトされます
私はできる必要があります
{{{map.setBounds(map.getBounds())}}}
そして何も起こらないように
マップの境界を設定しようとしています fitbounds は機能しません。境界の周りにスペースを配置するためです。
{{{map.fitBounds(map.getBounds())}}}
数回すると、マップがすばやくズームアウトされます
私はできる必要があります
{{{map.setBounds(map.getBounds())}}}
そして何も起こらないように
私が間違っていなければ、可能な限り最高のズーム レベルでマップ上にすべてのポイントを表示したいと考えていると思います。マップのズーム レベルを 16 に初期化することでこれを実現しました (V3 で可能な最高のズーム レベルかどうかはわかりません)。
var map = new google.maps.Map(document.getElementById('map_canvas'), { zoom: 16
, center: marker_point
, mapTypeId: google.maps.MapTypeId.ROADMAP
});
その後、私は境界のことをしました:
var bounds = new google.maps.LatLngBounds();
//you can have a loop here of all you marker points
//begin loop
bounds.extend(marker_point);
//end loop
map.fitBounds(bounds);
結果:成功!
FitBounds
あなたが言うように、境界を2番目のマップの境界を超えるように拡張します。境界をまったく同じにするために、中心とズームを設定できます。
map2.setCenter(map.getCenter());
map2.setZoom(map.getZoom());
この JSFiddle のように - http://jsfiddle.net/KmNaX/
Hey Guyzz、何も機能していなかったときに、このアプローチを計画しました..そしてそれは私のために機能しました..ビューポートから座標を取得し、同じものを境界にマッピングしました..このアプローチは機能します..
function codeAddress() {
var address = document.getElementById('address').value;
if(address == null || address== "") {
alert('Address field is Empty.. !');
} else {
geocoder.geocode({
'address' : address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// If geocoder status is OK then locate the geometry,..
var location = results[0].geometry.location
// Obtaining the lat lang of new position on map..
var latlng = new google.maps.LatLng(location.lat(),location.lng());
map.setCenter(location);
// view port gives us the map bounds for a particular location..
**var viewportloc = String(results[0].geometry.viewport);
var res = viewportloc.replace('((','').replace('))','').replace('(','').replace(')','').split(',');
//alert(res[0]+" - "+res[1]+" - "+res[2]+" - "+res[3]);
var sw = new google.maps.LatLng(res[0],res[1]);
var ne = new google.maps.LatLng(res[2],res[3]);
var bounds = new google.maps.LatLngBounds();
bounds.extend(sw);
bounds.extend(ne);
map.fitBounds(bounds);**
addMarker(location);
setonMap(map);
} else {
document.getElementById('address').value = "";
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
}