私のコードは次のとおりです。別のマーカーを追加し、そのマーカーをクリックして、代わりにそのマーカーの方向を表示できるようにしたいだけです。地図の下に運転ルートを作成する小さなフォームがあります。私はインターネット全体を見渡し、天の川銀河を検索しましたが、これを理解することはできません
<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>