javascript - Google Maps API 和显示位置

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

如何让显示的 map 居中位置略低于位置中心?

我发现我的信息窗口在顶部被 chop 了。

代码如下:

if(jQuery("#map").length)
{
    geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': 'andrade motor car 975 Campbell Avenue West Haven, CT 06516' }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var loc = results[0].geometry.location;
            var mapOptions = {
                zoom: 17,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                streetViewControl: false,
                mapTypeControl: false
            };
            map = new google.maps.Map(document.getElementById('map'), mapOptions);
            map.setCenter(loc);
            var marker = new google.maps.Marker({
                position: results[0].geometry.location,
                map: map//,
                //icon: new google.maps.MarkerImage("/assets/images/map_pointer.png", new google.maps.Size(38, 45), null, new google.maps.Point(18, 44))
            });         
            infobox = new google.maps.InfoWindow({
                maxWidth: 400,
                  content: '<div style="width:300px !important;overflow:hidden !important;"><h2 class="shop-title">andrade motor car</h2><p>975 Campbell Avenue<br />West Haven, CT 06516<br />203-931-7575</div>'
              });
            infobox.open(map, marker);
            map.panTo(new google.maps.LatLng(loc.lat(), loc.lng()));
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });     
}

我最初认为通过做类似的事情:

map.panTo(new google.maps.LatLng(loc.lat() - 1, loc.lng()));

可能有效果,但没什么区别

最佳答案

您可以使用 infoWindow 的 pixelOffset 选项来移动它,因为它适合您。例如:

var infowindow = new google.maps.InfoWindow({
    ...,
    pixelOffset: new google.maps.Size(20, 20)
});

关于javascript - Google Maps API 和显示位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20637109/

相关文章:

javascript - 循环创建变量,函数/数组循环

css - 为什么 IE 不在最后一个字母之后呈现字母间距?

html - CSS - 流程中断问题

java - 将位置数据从 fragment 传递到 Android 中的 Activity

google-maps - 从Kotlin的LatLng列表中获取LatLngBound的最佳方法

javascript - Prop 值未在子组件 Vue.js 中更新

javascript - 从 URL 在网页内执行 javascript 函数?

javascript - &lt;iframe&gt; 和它的文档之间的关系是一种方式吗?

css - 如何在此网页中锁定标题

google-maps - 如何在 Google Map V2 android 中将语言更改为波斯语