【问题标题】:google maps marker strangely stretched issue谷歌地图标记奇怪地拉伸问题
【发布时间】:2012-06-04 23:37:38
【问题描述】:

我遇到了谷歌地图的奇怪行为(见附图)有人知道这是怎么回事吗?以前有人经历过吗?

代码如下

<script>
<!--
    var map_geolocation;

    function savePosition_geolocation(point)
    {
        var input = document.getElementById("id_geolocation");
        input.value = point.lat().toFixed(6) + "," + point.lng().toFixed(6);
        map_geolocation.panTo(point);
    }

    function load_geolocation() {
        var point = new google.maps.LatLng(50.728632, 9.111587);

        var options = {
            zoom: 13,
            center: point,
            mapTypeId: google.maps.MapTypeId.ROADMAP
            // mapTypeControl: true,
            // navigationControl: true
        };

        map_geolocation = new google.maps.Map(document.getElementById("map_geolocation"), options);

        var marker = new google.maps.Marker({
                map: map_geolocation,
                position: new google.maps.LatLng(50.728632, 9.111587),
                draggable: true

        });
        google.maps.event.addListener(marker, 'dragend', function(mouseEvent) {
            savePosition_geolocation(mouseEvent.latLng);
        });

        google.maps.event.addListener(map_geolocation, 'click', function(mouseEvent){
            marker.setPosition(mouseEvent.latLng);
            savePosition_geolocation(mouseEvent.latLng);
        });

    }

    $(function() {
        load_geolocation();
    });

//-->
</script>
        <input type="hidden" name="geolocation" value="50.728632,9.111587" id="id_geolocation" /><div id="map_geolocation" style="width: 400px; height: 300px"></div>

【问题讨论】:

  • 我注意到当我从 MarkerOptions 中删除可拖动时,它看起来很正常

标签: jquery google-maps-api-3


【解决方案1】:

我见过各种形式的拉伸图块和扭曲的控件,但这是我第一次看到拉伸标记和阴影。如果我们幸运的话,将这些行添加到您的 CSS 或样式中将不会拉伸地图和标记。

 #map_geolocation label { width: auto; display:inline; }
 #map_geolocation img { max-height: none; max-width: none; }

我试过你附加的代码,它看起来不错。

【讨论】:

  • 这有助于在我构建响应式地图时展开平移和缩放控件。干杯!
【解决方案2】:

你在使用 twitter 引导程序吗? 如果是这样,请尝试添加以下样式表。

div#map_geolocation img {
  max-width:none;
}

【讨论】:

  • 是的,这就像一个魅力!忘记了 TB 会影响 img 的宽度。
【解决方案3】:

对于那些在 Google Maps JavaScript API 的较新版本 (v3.33+) 2018-2019 上遇到此问题的人。我建议检查这篇文章: https://stackoverflow.com/a/54140395/8658147 也是。

【讨论】:

猜你喜欢
  • 2013-12-09
  • 2013-09-21
  • 2011-04-04
  • 1970-01-01
  • 2012-08-07
  • 2021-12-23
  • 2017-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多