我在数据库中有一组坐标,我想用它在谷歌地图上添加标记
我创建了以下代码
var map;
function initialize()
{
var latloncenter = new google.maps.LatLng(51,-1.4469157);
var myOptions =
{
zoom: 4,
center: latloncenter,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
};
<? while($row = mysql_fetch_assoc($result)){?>
var lon = "<?php echo($row['Longitude']); ?>";
var lat = "<?php echo($row['Latitude']); ?>";
//alert_test(lat,lon);
setmarker(lat,lon);
<? } ?>
function setmarker(lat,lon)
{
var latlongMarker = new google.maps.LatLng(lat,lon);
var marker = new google.maps.Marker
(
{
position: latlongMarker,
map: map,
title:"Hello World!"
}
);
}
function alert_test(lat,lon)
{
alert(lat +" "+ lon);
}
<body onload="initialize()"><div id="map_canvas"></div></body>
它正在加载地图,我知道来自数据库的查询工作正常,但是我认为我在 setmarker() 方法中做错了....有人知道如何让它工作吗?