javascript - 谷歌将API中心映射到正确的位置,但箭头指向不同的位置

标签 javascript google-maps google-maps-api-3

我正在使用 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 正确地居中在正确的位置,但指针始终位于左侧,而不是指向该位置。这是一个屏幕截图: the place

如何移动指针?我确信答案很简单,但我遇到了麻烦。

最佳答案

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/

相关文章:

javascript - 单击一个时关闭所有其他信息窗口

javascript - 如何在网页上的谷歌地图上添加地址?

javascript - google map place API如何从建议中删除国家名称

google-maps - 两个经纬度点之间的距离

javascript - 如何在谷歌地图中隐藏河流和湖泊?

javascript - Google map 标记数组对象未显示

javascript - 我收到错误消息 : "Cannot read property ' push' of undefined"

javascript - 如何通过仅将鼠标悬停在父级上来调节子级的样式?

javascript - 注入(inject) <SCRIPT> 标签,为其提供正确的位置

javascript - 更改 jQuery UI Datepicker 的位置