我通过使用GMAP解决了这个问题。js。
function initMap($el) {
var bounds = [];
var waypts = [];
var $markers = $($el).find(\'.marker\');
var map = new GMaps({
div: $el,
scrollwheel: false,
zoomControl : true,
zoomControlOpt: {
style: \'LARGE\',
position: \'TOP_RIGHT\'
},
panControlOpt: {
position: \'TOP_RIGHT\'
}
});
$markers.each(function() {
// DEFINE CURRENT/NEXT MARKER
$this = $(this);
$next = $(this).next();
// DEFINE BOUNDS
var latlng = new google.maps.LatLng($(this).data(\'lat\'), $(this).data(\'lng\'));
bounds.push(latlng);
if( $next.length != 0 ) {
waypts.push({
location: $next .find(\'.address\').html(),
stopover: true
});
}
// MARKERS
map.addMarker({
lat: $(this).data(\'lat\'),
lng: $(this).data(\'lng\'),
icon: $(this).data(\'icon\'),
infoWindow: {
content: $(this).html()
}
});
});
map.drawRoute({
origin: [$markers.first().data(\'lat\'), $markers.first().data(\'lng\')],
destination: [$markers.last().data(\'lat\'), $markers.last().data(\'lng\')],
waypoints: waypts,
travelMode: \'driving\',
strokeColor: \'#F1594D\',
strokeOpacity: 1,
strokeWeight: 4
});
// STYLE
var styles = [{featureType:\'water\',stylers:[{color:\'#70B6E9\'},{visibility:\'on\'}]},{featureType:\'landscape\',stylers:[{color:\'#E8E1D9\'}] },{featureType:\'road\',stylers:[{saturation:-100},{lightness:45}]},{featureType:\'road.highway\',stylers:[{visibility:\'simplified\'}] },{featureType:\'road.arterial\',elementType:\'labels.icon\', stylers:[{visibility:\'off\'}] },{featureType:\'administrative\',elementType:\'labels.text.fill\',stylers:[{color:\'#444444\'}] },{featureType:\'transit\', stylers:[{visibility:\'off\'}] },{featureType:\'poi\', stylers:[{visibility:\'off\'}] }];
map.addStyle({
styledMapName:"Styled Map",
styles: styles,
mapTypeId: "map_style"
});
map.setStyle("map_style");
map.fitLatLngBounds(bounds);
}
$(\'.js-TourMap\').each(function() {
initMap(\'#\' + $(this).attr(\'id\'));
})