【发布时间】:2015-03-23 01:15:27
【问题描述】:
我在网上找到了一个很棒的代码,我正在尝试使用按钮将标记移动到另一个位置。我想我需要用点击事件触发变量“targetLocation”,但我不知道怎么做。还是应该创建像 targetlocation2 和 marker2 这样的变量?
位置 1:41.118555",28.2743889
位置 2:38.9152733,-111.6676686
html:
<a href="#location1">Address 1</a>
<a href="#location2">Address 2</a>
代码:
if ($("#map .google-maps").length) {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var targetLocation = new google.maps.LatLng("41.118555", "28.2743889");
var myOptions = {
center: targetLocation,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 13,
scrollwheel: false,
streetViewControl: false,
mapTypeControl: false,
disableDoubleClickZoom: true,
styles: [
{
featureType: "all",
stylers: [
{saturation: -100}
]
}
]
}
var map = new google.maps.Map($("#map .google-maps")[0], myOptions);
directionsDisplay.setMap(map);
var marker = new google.maps.Marker({
position: targetLocation,
map: map,
icon: "marker.png",
visible: true
});
}
【问题讨论】:
标签: jquery google-maps-api-3 google-maps-markers