在这里,我有标记作为 Json 对象作为响应,这些标记正在谷歌地图上显示。在这里,我想在这些标记之间绘制路径,但萤火虫显示(value.Latitude)的错误无效值。这里的值是我的 JSON 对象。
var request = {
origin:value.Latitude,
destination:value.Longitude,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
这是我的整个脚本
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<style type="text/css">
#map_canvas {
height: 500px;
width: 800px;
position: static;
top: 0px;
left: 100px;
}
</style>
<script>
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
function initialize() {
var latlng = new google.maps.LatLng(18.5236, 73.8478);
directionsDisplay = new google.maps.DirectionsRenderer();
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false,
mapTypeControl: false
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
directionsDisplay.setMap(map);
$(document).ready(function () {
$("#btnSubmit").click(function () {
var Source = $("#Source").val();
var Destination = $("#Destination").val();
authenticate(Source, Destination);
});
});
function authenticate(Source,Destination) {
$('#somediv').empty();
var table = $('<table/>').appendTo($('#somediv'));
$.ajax
({
type: 'GET',
url: 'REST/WebService/GetLogin',
dataType: 'json',
data:{'Source': Source, 'Destination': Destination },
error:function()
{
alert("unsuccessfull");
},
success:function(feeds)
{
alert(feeds.length);
$.each(feeds, function (index, value) {
new google.maps.Marker({
position: new google.maps.LatLng(value.Latitude,value.Longitude),
map: map,
title: "Marker Placing"
});
var request = {
origin:value.Latitude,
destination:value.Longitude,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
});
//alert(feeds.toSource());
}
});
}
}
</script>