在我的数据库中,我有lat/lng值,我试图在谷歌地图上显示标记。(我有我的地图,但不能得到标记!)。
// Selects all the rows in the tester table.
$query = 'SELECT * FROM tester WHERE 1';
$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_assoc($result))
{?>
var marker = new google.maps.Marker({
position: <?php $row['lat']?>, <?php $row['lng']?> ,
map: map,
title:"Hello World!"
});
}
任何帮助将是伟大的谢谢!
我认为你需要使用"echo":
position: <?php echo $row['lat']?>, <?php echo $row['lng']?> ,
当你开始从PHP中编写javascript时,它变得相当复杂,因为它很容易迷失在所有的分号中。
我也发现用PHP做这些事情比在HTML-PHP-HTML-PHP之间跳来跳去更容易
试试这个
// Selects all the rows in the tester table.
$query = 'SELECT * FROM tester WHERE 1';
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
echo '<script type="text/javascript">';
$i = 0;
while ($row = mysql_fetch_assoc($result))
echo 'var myLatlng = new google.maps.LatLng(' . $row['lat'] ',' . $row['lng'] . ');';
echo 'var marker' . $i . ' = new google.maps.Marker({';
echo ' position: myLatLng ,';
echo ' map: map,';
echo ' title:"Hello World!"';
echo '});';
echo 'marker' . $i . 'setMap(map);';
$i++;
}
echo '<script>';