gpt4 book ai didi

javascript - Google Maps API 和显示位置

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:26 24 4
gpt4 key购买 nike

如何让显示的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com