Google 地图:计算 div 叠加层未覆盖的位置

Google Maps: Calculate position not covered by div overlay

以下情况:

碰撞复选框与标记不是问题,但我无法让它相应地移动地图。

这是我试过的:

google.maps.event.addListenerOnce($scope.map, "projection_changed", function() {
    $scope.projection = $scope.map.getProjection();
});

var sidebar = document.getElementById('sidebar');
var rect = sidebar.getBoundingClientRect();

var marker = $scope.mainmarker.getPosition();
marker = $scope.projection.fromLatLngToPoint(marker); 
marker.x = rect.left / 2;
marker = $scope.projection.fromPointToLatLng(marker);
$scope.map.setCenter(marker);

但据我所见,地图移动得太远了。

我选择了这个对我来说效果很好的解决方案:

   if (underneath === true) {
        var marker = $scope.mainmarker.getPosition();
        var pixelpoint = $scope.projection.fromLatLngToPoint(point);
        pixelpoint.x += 250 / Math.pow(2, $scope.map.getZoom());
        point = $scope.projection.fromPointToLatLng(pixelpoint);
        $scope.map.setCenter(point);
    }