如何在wordpress中增加谷歌地图的缩放级别
问题描述:
这里是我写的代码,通过提供纬度和经度向谷歌地图添加标记。问题是我没有得到缩放谷歌地图。我尝试将缩放级别设置为12,但这对封闭的地图没有影响。如何在wordpress中增加谷歌地图的缩放级别
<script type="text/javascript">
var lat = 49.892231;
var lng = -97.132530;
var zoomLevel = 12;
var allMarkers = [];
var curMarkerInder = 0;
var site_url = "<?php echo bloginfo('stylesheet_directory') ?>";
var map_left = 270;
var map_top = 234;
var bounds ;
function open_window(markerId){
GEvent.trigger(allMarkers[markerId-1],"click");
}
if (latLangs.length > 0){
var mapOptions = {
center: new google.maps.LatLng(lat, lng),
zoom: zoomLevel,
scrollwheel: false,
draggable: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
bounds = new google.maps.LatLngBounds();
}else{
$("#map").remove();
}
function markeradd(lat,lng,content){
var image = site_url + "/images/red.png"
var markerOptions = {
map: map,
icon: image,
position: new google.maps.LatLng(lat,lng)
};
var marker = new google.maps.Marker(markerOptions);
var content = content;
google.maps.event.addListener(marker, 'click', function(e) {
var infobox = new SmartInfoWindow({
position: marker.getPosition(),
map: map,
content: content
});
});
var myLatLng = new google.maps.LatLng(lat,lng);
bounds.extend(myLatLng);
//map.setCenter(myLatLng);
//map.setZoom(zoomLevel);
}
jQuery(document).ready(function($) {
function createMarker(point,html,i) {
var image = site_url + "/images/red.png"
var Icon = new GIcon();
Icon.image = image;
Icon.iconSize = new GSize(30, 52);
Icon.shadowSize = new GSize(36, 34);
Icon.iconAnchor = new GPoint(5, 34);
Icon.infoWindowAnchor = new GPoint(5, 2);
Icon.infoShadowAnchor = new GPoint(14, 25);
opts = {
"icon": Icon,
"labelText": "A",
"labelOffset": new GSize(-6, -10),
"clickable": true
};
var marker = new GMarker(point,opts);
allMarkers[i] = marker;
marker.hide();
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
last_marker = marker;
});
return marker;
}
for(var i=0; i < latLangs.length; i++) {
markeradd(latLangs[i]['lat'],latLangs[i]['lng'],latLangs[i]['address']);
}
map.fitBounds(bounds);
$("#menu-item-3122").addClass('current_page_item');
$("#menu-item-3123").addClass('current_page_item');
});
</script>
如何提高这种情况下的缩放级别? 请给我任何建议...
答
该地图正在缩放以适合标记,因为它编码在这里:map.fitBounds(bounds);
。
要停止发生这种情况,请删除该行。
地图是否缩放以适应标记,因为您编码它('map.fitBounds(bounds);')?如果是这种情况,您可以通过删除该行来防止它改变缩放级别。 – geocodezip
谢谢......我的问题解决了。 :) –