【发布时间】:2014-03-15 21:47:31
【问题描述】:
站点应用程序,可将用户从当前位置带到特定位置并提供目的地详细信息。我有两个问题。首先,我无法弄清楚如何更改两点之间的折线颜色。默认为蓝色,但我似乎无法覆盖它。
还有,一旦生成了目的地,我该如何去除这些标记?
我应该在下面的代码中把这个 sn-p 放在哪里才能工作?
var polylineOptions = {
strokeColor:"#FF0000",
strokeOpacity: 1,
strokeWeight: 2,
zIndex: 5
}
这是 google map js 的其余部分。
var directionsService = new google.maps.DirectionsService(),
directionsDisplay = new google.maps.DirectionsRenderer(),
createMap = function (start) {
var travel = {
origin: (start.coords) ? new google.maps.LatLng(start.lat, start.lng) : start.address,
destination: customPosition,
travelMode: google.maps.DirectionsTravelMode.DRIVING
// Exchanging DRIVING to WALKING above can prove quite amusing :-)
},
map = new google.maps.Map(document.getElementById("map"), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("map-directions"));
directionsService.route(travel, function (result, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
var marker = new google.maps.Marker({
position: customPosition,
map: map,
clickable: false,
icon: 'images/minilogo.png',
animation: google.maps.Animation.DROP,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
}
});
});
};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
// Success!
enableHighAccuracy: true,
$("#map-directions").show();
$("#geo").each(function () {
$(this).animate({
opacity: 0.5
}, 1000);
$(this).unbind();
$(this).html("<a>Position funnen!</a>");
});
console.log("that worked like a charm");
createMap({
polylineOptions:{strokeColor:'red'},
suppressMarkers:true,
coords: true,
lat: position.coords.latitude,
lng: position.coords.longitude
});
}, function errorCallback(error) {
// Gelocation fallback: Defaults to Stockholm, Sweden
console.log("Something went wrong, fallback initalized");
$("#geo").html("<a>Kunde inte hitta din position - pröva igen</a>");
$("#map-directions").hide();
$("#map-directions").unbind();
createMap({
coords: true,
address: customPosition,
zoom: 15
});
}, {
maximumAge: Infinity,
timeout: 10000
});
} else {
// No geolocation fallback: Defaults to Lisbon, Portugal
$('#geo').html('<p>Old browser, cannot run function</p>');
$("#map-directions").hide();
createMap({
coords: true,
address: customPosition
});
} //else
非常感谢!
【问题讨论】:
标签: javascript jquery google-maps