【问题标题】:Google Maps V3 multiple markers with directionsGoogle Maps V3 带有方向的多个标记
【发布时间】:2011-03-03 14:43:47
【问题描述】:

我的代码在下面我只想添加另一个标记并能够单击该标记并显示该标记的方向。在地图下方有一个生成行车路线的小表格。我已经在整个互联网上搜索并搜索了银河系,但我无法弄清楚这件事

    <h2>Get Driving Directions</h2> 
    <p>
        <label> coming from: <input class="roundInput" id="to-input" type="text" value="" /> </label> <input style="position:relative;top:6px;" type="image" src="<?php bloginfo('template_directory'); ?>/img/route_button.gif" value="route" onclick="doDirections()" /> 
    <div id="dynamicDirections" style="margin-left:30px">
    </div>
    </p>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript">
// <![CDATA[

    var psGlobals={
        address:'3908 Aurora Ave N, Seattle, WA 98103 ',
        lat:47.6545077,
        lon:-122.3471123,
        zoomlevel:13
    };


    function initialize() 
    { 
        psGlobals.latlng = new google.maps.LatLng(psGlobals.lat, psGlobals.lon);
        buildMap();
        psGlobals.dirRenderer = new google.maps.DirectionsRenderer();
        psGlobals.dirService = new google.maps.DirectionsService();
    }

    function buildMap()
    {
        var myOptions, marker;
        myOptions = {
              navigationControl: true,
              navigationControlOptions: {
                  style: google.maps.NavigationControlStyle.ZOOM_PAN
                },

              mapTypeControl: true,
              scaleControl: false,
              zoom: psGlobals.zoomlevel,
              center: psGlobals.latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        psGlobals.map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        psGlobals.marker = new google.maps.Marker({
            position: psGlobals.latlng, 
            map: psGlobals.map,
            title:"4Evergreengroup"
        });


    }

    function doDirections()
    {
        var fromStr = $('#to-input').val();

        var dirRequest = {
            origin: fromStr,
            destination: psGlobals.address,
            travelMode: google.maps.DirectionsTravelMode.DRIVING,
            unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL
        };
        psGlobals.dirService.route(dirRequest, handleDirections);
    }

    function handleDirections(dirResult,dirStatus)
    {
        if (dirStatus != google.maps.DirectionsStatus.OK) 
        {
            alert('Directions failed: ' + dirStatus);
            return;
        }

        psGlobals.dirRenderer.setMap(psGlobals.map);
        psGlobals.dirRenderer.setPanel(document.getElementById('dynamicDirections'));
        psGlobals.dirRenderer.setDirections(dirResult);
  }

  $(document).ready(function(){initialize()});

// ]]>

</script> 

【问题讨论】:

  • 检查 Google Maps Directions API。您也可以查看this code

标签: google-maps google-maps-markers directions


【解决方案1】:

不确定这是否能回答您的问题。这是您的代码:

http://bobcravens.com/demos/temp/gmap1.html

单击“路线”按钮会生成并插入路线。您的原始代码对我不起作用。我添加了 'map_canvas' div 来为 google.maps 提供目标。似乎现在可以工作了。让我知道是否还有更多?

鲍勃

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    • 2012-08-27
    • 2018-09-06
    相关资源
    最近更新 更多