我们是否有选择在右侧位置而不是中心点显示谷歌地图标记 HTML
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var lan = 11.4602
var lat = 47.7493
var infoWindowContent = "Info Content";
var zoom = 14;
createMap( lat, lan,zoom,infoWindowContent );
}
function createMap(lat, lng, zoomVal,infoWindowContent ) {
var infoText_32 = infoWindowContent;
infoText_32 = decodeURIComponent(infoText_32);
infoText_32 = infoText_32.replace(/\+/g, ' ');
// split infoText into rows
var rowsInfoText_32 = infoText_32.split("<br>");
var latlng_32 = new google.maps.LatLng(lat,lng);
var mapOptions_32 = new Object();
mapOptions_32.center = latlng_32;
mapOptions_32.zoom = zoomVal;
mapOptions_32.mapTypeId = google.maps.MapTypeId.ROADMAP;
mapOptions_32.navigationControlOptions = new Object();
mapOptions_32.navigationControlOptions.style = google.maps.NavigationControlStyle.DEFAULT;
mapOptions_32.scrollwheel = true;
//myOptions.navigationControlOptions = {style: google.maps.NavigationControlStyle.SMALL};
var mapCenter_32 = new Object();
mapCenter_32.position = latlng_32;
mapCenter_32.title = rowsInfoText_32[0];
mapCenter_32.icon = 'map-icon.png';
var map_32 = new google.maps.Map(document.getElementById(""), mapOptions_32);
var marker_32 = new google.maps.Marker(mapCenter_32);
// set info window
if ('' != infoText_32){
infoText_32 = infoText_32.replace(/\n/g, "<br>");
var infoBox_32 = new Object();
infoBox_32.content = infoText_32;
var infowindow_32 = new google.maps.InfoWindow(infoBox_32);
// add listener
google.maps.event.addListener(marker_32, 'click', function(){openInfoWindow_32();});
}
if (true == '') {
// show map, open infoBox and center view
google.maps.event.addListener(map_32, 'tilesloaded',
function(){google.maps.event.trigger(marker_32, 'click');});
}
marker_32.setMap(map_32);
function openInfoWindow_32(){
infowindow_32.open(map_32,marker_32);
}
}
的Javascript
FROM
我们如何在Google地图中将我们的标记设置在右侧位置
如果你得到任何适当的线索,请告诉我
答案 0 :(得分:2)
有一种方法可以在Google地图中定义marker offset。
var marker = new google.maps.Marker({
position:new google.maps.LatLng(36,-80),
icon: {
url: 'images/beachflag.png',
size: new google.maps.Size(20, 32),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 32)
}
//more attributes
});
这是直接从给定网址上的示例中获取的。
本质上,它是一个对象,具有关于图像源(url
)的属性,以及大小,原点和定位值。这很简单。要使标记位于标记的左侧侧,请使用anchor: new google.maps.Point(32,32)
或图像的高度和宽度。要使图像位于标记的右侧侧(如示例所示),请使用anchor: new google.maps.Point(0,32)
或0
以及标记的高度。