我正在使用 Google map API。它在大多数情况下都有效,但我无法让箭头指向正确的位置。这是我的代码:
<div id="map1" style="height: 200px"></div>
<script>
function createInfoWindowContent() {
return ['the place', 'the city'].join('<br>');
}
google.maps.event.addDomListener(window, 'load', init);
function init() {
// Options for Google map
// More info see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
var mapOptions1 = {
zoom: 14,
center: new google.maps.LatLng(42.366012, -71.098702)
// Style for Google Maps
};
// Get all html elements for map
var mapElement1 = document.getElementById('map1');
// Create the Google Map using elements
var map1 = new google.maps.Map(mapElement1, mapOptions1);
var coordInfoWindow = new google.maps.InfoWindow();
coordInfoWindow.setContent(createInfoWindowContent());
coordInfoWindow.open(map1);
}
</script>
上面的代码确实将 map 正确地居中在正确的位置,但指针始终位于左侧,而不是指向该位置。这是一个屏幕截图:
如何移动指针?我确信答案很简单,但我遇到了麻烦。
最佳答案
open 方法的第二个对象采用 anchor 对象:
coordInfoWindow.open(map1,{position:map1.getCenter()})
引用:https://developers.google.com/maps/documentation/javascript/3.exp/reference#InfoWindow
关于javascript - 谷歌将API中心映射到正确的位置,但箭头指向不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30651912/