我对下面的代码有一点问题。
我在一个 php 文件中使用此代码,从数据库中获取一些地址并将它们固定在地图上。我的问题是:如果我不知道 lon lat 坐标,如何将地图渲染到中心?我尝试使用 map: {center: true, zoom: 7} (代码在这里不合适,但在我的代码中)但它不起作用。
所以我想,如果可以说我可以得到我用标记固定的市中心的经度和纬度,那么它可能是地图的中心。在下面的示例中,如果我可以获得“城市”的经纬度坐标,那么我可以将其作为中心点。
我需要这方面的帮助,或者如果有更简单的解决方案,我将不胜感激您的回复。
提前谢谢了。彼得
<script type="text/javascript">
$(function(){
$('#test1')
.gmap3(
{ action:'init',
options:{
center:[46.578498,2.457275],
zoom: 7
}
},
{ action: 'addMarkers',
markers:[
{address: "City address 1, Country", data:'Hello1'},
{address: "City address 2, Country", data:'Hello2'},
{address: "City address 3, Country", data:'Hello3'}
],
marker:{
options:{
icon: new google.maps.MarkerImage('img/gmap_pin_stay.png'),
draggable: false
},
events:{
click: function(marker, event, data){
var map = $(this).gmap3('get'),
infowindow = $(this).gmap3({action:'get', name:'infowindow'});
if (infowindow){
infowindow.open(map, marker);
infowindow.setContent(data);
} else {
$(this).gmap3({action:'addinfowindow', anchor:marker, options:
{content: data}});
}
},
}
}
}
);
});
</script>