我正在使用谷歌地图并尝试制作一些外部链接标记。我正在用异步加载它,然后尝试制作具有外部链接的标记,然后可以单击这些链接以动画到标记。我所拥有的不是很有效,但我认为它已经接近了。我也想知道如何使用 jquery 来做到这一点?我认为部分问题是我无权访问 body 标签,所以我不能这样做,我不知道该怎么做。
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&' +
'callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;
var marker1;
var marker2;
function initialize() {
var latlng = new google.maps.LatLng(26.032260, 50.514686);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var infowindow = new google.maps.InfoWindow();
marker1 = new google.maps.Marker({ position: new
google.maps.LatLng(41.569690, 2.257090), map: map, title: 'Barcelona' });
google.maps.event.addListener(marker1, 'click', function() {
infowindow.setContent('Spanish Grand Prix');
infowindow.open(map, marker1);
});
marker2 = new google.maps.Marker({ position: new
google.maps.LatLng(31.338463, 121.220355), map: map, title: 'Shanghai'});
google.maps.event.addListener(marker2, 'click', function() {
infowindow.setContent('Chinese Grand Prix');
infowindow.open(map, marker2);
});
}