उन लोगों के लिए था टी एक उदाहरण की जरूरत है जैसे मैंने किया था, यहाँ एक बुनियादी एक है:
// Map and directions objects
var map = new google.maps.Map(element, options);
var service = new google.maps.DirectionsService();
var directions = new google.maps.DirectionsRenderer({suppressMarkers: true});
// Start/Finish icons
var icons = {
start: new google.maps.MarkerImage(
// URL
'start.png',
// (width,height)
new google.maps.Size(44, 32),
// The origin point (x,y)
new google.maps.Point(0, 0),
// The anchor point (x,y)
new google.maps.Point(22, 32)
),
end: new google.maps.MarkerImage(
// URL
'end.png',
// (width,height)
new google.maps.Size(44, 32),
// The origin point (x,y)
new google.maps.Point(0, 0),
// The anchor point (x,y)
new google.maps.Point(22, 32)
)
};
service.route({ origin: origin, destination: destination }, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
display.setDirections(response);
var leg = response.routes[ 0 ].legs[ 0 ];
makeMarker(leg.start_location, icons.start, "title");
makeMarker(leg.end_location, icons.end, 'title');
}
});
function makeMarker(position, icon, title) {
new google.maps.Marker({
position: position,
map: map,
icon: icon,
title: title
});
}
एक मार्ग अनुरोध से प्रतिक्रिया एक पैर (रों) अपने मार्ग पर बंद हो जाता है की संख्या के आधार देता है। मैं केवल ए टू बी रूट कर रहा हूं, इसलिए केवल पहला चरण लें, और मार्करों को कहां जाना है, और उन स्थानों के लिए मार्कर बनाने की स्थिति प्राप्त करें।
स्रोत
2011-03-04 22:18:21
मार्करों को दिशानिर्देशों के भीतर बदलने के बारे में क्या? – Jason
हाँ, अच्छा सवाल है! – keatch
मैंने दूसरी बार दिशानिर्देशों की गणना करने से पहले सभी मार्करों को साफ़ करने के लिए कार्यक्षमता जोड़ा। Https://developers.google.com/maps/documentation/javascript/examples/marker-remove – lmeurs