谷歌地图标记

时间:2011-07-15 06:24:17

标签: javascript

我正试图在我的应用程序中插入谷歌地图。

我想标记从源到目的地的位置,两者都提供。

我是JavaScript新手,所以请帮助我。

我现在使用的代码是:

   <script type="text/javascript">

        function initialize()
         {
             if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(37.4419, -122.1419), 13);
            var polyline = new GPolyline([
            new GLatLng(37.4419, -122.1419),
            new GLatLng(37.4519, -122.1519)
            ], "#ff0000", 10);
            map.addOverlay(polyline);
            }
        }​​
</script>

如何导入与此代码相关的google api?

1 个答案:

答案 0 :(得分:3)

由于GMap2(...),您正在使用API​​ V2。在这种情况下插入

<script type="text/javascript"
        src="http://maps.google.com/mapsfile=api&amp;v=2&amp;key=KEY&amp;sensor=false">
</script> 

进入HTML文档的<head>部分。 KEY是您可以从Google获得的Google API密钥。但是,最好使用API​​的版本V3 。那你就不需要钥匙了。在V3中插入

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> 
</script>

进入HTML文档的<head>部分。 另请参阅Google Map API v3 tutorial。在您的文档中,您应该有一个<div id="map_canvas" ...></div>。地图V3创建为

 var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
相关问题