2013-12-14 40 views
-1

如何獲取此Google地圖以調整到折線界限的界限?Google地圖的折線界限

http://goo.gl/hjOcAx

我想我是正確使用此:

var bounds = new google.maps.LatLngBounds(); 
    decodedPath.getPath().forEach(function(LatLng) { 
    bounds.extend(LatLng); 
}); 
map.setBounds(bounds); 

但我也認爲,我把它放錯了地方。

+0

v3中沒有'GPolyline.getBounds()',因爲它存在於v2中。 Javascript不是我的強項,但我很樂意爲此尋找解決方案 – user1194034

回答

0
  1. decodedPath是一條路徑(不是Polyline),並且沒有方法getPath()。 使用:

    decodedPath.forEach(function(LatLng) { 
        bounds.extend(LatLng); 
    }); 
    
  2. 沒有方法setBounds(),使用fitBounds()代替。
+0

謝謝!我還從myLatlng變量中刪除了硬編碼的lat和lng字段,並從myOptions變量中移除了'center'和'zoom'屬性,作爲fitBounds()方法。奇蹟般有效 :) – user1194034