0

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

    <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> 
4

1 回答 1

0

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

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

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

鲍勃

于 2011-03-03T15:03:59.997 回答