【发布时间】:2014-03-28 20:32:17
【问题描述】:
我正在尝试修改现有主题的 js,以便能够在地图上显示不同的位置。 这是原始代码:
function initialize() {
var map;
var brooklyn = new google.maps.LatLng(parseFloat("<?php echo $coordinates[0]; ?>"), parseFloat("<?php echo $coordinates[1]; ?>"));
var stylez = [{
featureType: "all",
elementType: "all",
stylers: [{
saturation: -100
} // <-- THIS
]
}];
var mapOptions = {
zoom: parseInt("<?php the_field("google_map_zoom_level"); ?>"),
center: brooklyn,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'tehgrayz']
}
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
var mapType = new google.maps.StyledMapType(stylez, {
name: "Grayscale"
});
map.mapTypes.set('tehgrayz', mapType);
map.setMapTypeId('tehgrayz');
marker = new google.maps.Marker({
title: "<?php echo $map["
address "]; ?>",
position: new google.maps.LatLng(parseFloat("<?php echo $coordinates[0]; ?>"), parseFloat("<?php echo $coordinates[1]; ?>")),
map: map
});
}
initialize();
//google.maps.event.addDomListener(window, 'load', initialize);
}
我还设法使用各种教程创建了一个将标记移动到新位置的函数。
function changeMarkerPos(lat, lon){
myLatLng = new google.maps.LatLng(lat, lon);
marker.setPosition(myLatLng);
map.panTo(myLatLng);
}
但是,尽管标记确实移动了,但地图并没有按照我的意愿居中。谁能帮我吗?我对js不太好,所以请保持简单...
谢谢!!!
【问题讨论】:
标签: javascript google-maps google-maps-markers