2010-02-16 52 views
0

我希望我的导航页面具有与this页面相同的功能,即Google地图对象从右边的表格更新。我怎么能在我的网页上有这个?我正在使用Django顺便说一句,但我认为这不会有太大的影响......对于这样的事情,实现应该是普遍的。在方向页面嵌入谷歌地图地图

回答

1

我已经在Drupal站点内完成了这项工作。代码API非常简单。您可以使用经度和纬度作为中心点生成初始交互式地图。

function initialize() { 

     if (GBrowserIsCompatible()) { 
     var map = new GMap2(document.getElementById("map_canvas")); 
     map.setCenter(new GLatLng(37.4419, -122.1419), 13); 
     } 
    } 

然后,您需要将您的路线表格打电话给Google Geocoder。这将把输入的地址变成经度和地位 - 尽管你也许可以绕过这一步。

然后,使用新获得的Long & Lat来生成方向请求(再次使用Google API)。

// Create a directions object and register a map and DIV to hold the 
// resulting computed directions 

var map; 
var directionsPanel; 
var directions; 

function initialize() { 
    map = new GMap2(document.getElementById("map_canvas")); 
    map.setCenter(new GLatLng(42.351505,-71.094455), 15); 
    directionsPanel = document.getElementById("route"); 
    directions = new GDirections(map, directionsPanel); 
    directions.load("from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)"); 
} 

所有的Javascript都可以直接进入你的HTML。我建议你花点时间研究http://code.google.com/apis/ajax/playground/