Google Maps API和显示位置

时间:2013-12-17 14:42:46

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

如何让显示的地图中心位置略低于位置的中心?

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

以下是代码:

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()));

可能会成功,但没有区别

1 个答案:

答案 0 :(得分:1)

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

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