我的代码在下面我只是想添加另一个标记,并且能够点击该标记并显示该指示。有一个小形式可以在地图下方生成行车路线。我看了整个互联网,搜索了银河系的星系,我无法理解这个问题
<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>
答案 0 :(得分:0)
不确定这是否回答了您的问题。这是你的代码:
http://bobcravens.com/demos/temp/gmap1.html
单击“路线”按钮可生成并插入路线。你原来的代码不适合我。我添加了'map_canvas'div来为google.maps提供目标。似乎现在工作。让我知道是否还有更多?
鲍勃