我有一个谷歌地图,它使用谷歌地图使用标准Directions API计算从点A到点B的路线。在这个地图上我有我从database获得的自定义标记。我想知道哪些标记与所选路线相交。谷歌地图的方向APIv3与自定义标记
我创建了一个拨弄了所有必要的代码段,但地图似乎并不在的jsfiddle :(
http://jsfiddle.net/Fumunchu/94kLnrr7/2/ 这里产生是我的JavaScript来生成地图,并添加标记
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var lati = -33.9149861;
var longi = 18.6560594;
var markers;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(lati, longi);
var mapOptions = {
zoom: 9,
center: chicago
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
markers = $.getJSON("http://secure.transcommercial.co.za/API/Toll", function (data) {
for (var i = 0; i < ko.toJS(data).length; i++) {
new google.maps.Marker({
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(ko.toJS(data)[i].TollLatitude, ko.toJS(data)[i].TollLongitude),
map: map,
icon: "http://maps.google.com/mapfiles/ms/icons/blue-dot.png"
});
}
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
});
}
}
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
任何意见,将不胜感激!
问题是什么? – geocodezip 2015-04-03 13:23:06
什么是'ko.toJS'? – geocodezip 2015-04-03 13:28:00
@geocodezip我在我的ASP MVC应用程序中使用http://knockoutjs.com/documentation/json-data.html。所有ko.toJS都会将对象从我的API转换为可用格式,在这种情况下为float。 – 2015-04-03 13:35:25