如何将php结果传递给google maps
我使用这段php代码从MySQL数据库中检索lat和lon,结果值应该作为google map的输入。因此,当我运行查询时,输出应该转到google maps。作为参数,我如何才能做到这一点 这是php代码。如何将php结果传递给google maps,php,mysql,google-maps,google-maps-api-3,Php,Mysql,Google Maps,Google Maps Api 3,我使用这段php代码从MySQL数据库中检索lat和lon,结果值应该作为google map的输入。因此,当我运行查询时,输出应该转到google maps。作为参数,我如何才能做到这一点 这是php代码。 mysql_select_db("theatdb", $con); $result = mysql_query("SELECT Lat,Lon FROM theaters WHERE theater_name='theater_name'"); whil
mysql_select_db("theatdb", $con);
$result = mysql_query("SELECT Lat,Lon FROM theaters
WHERE theater_name='theater_name'");
while($row = mysql_fetch_array($result))
{
echo $row['theater_name'];
echo "<br />";
}
?>
php代码正在检索要将结果传递给google maps的lat和lon值。我如何才能做到这一点?有人帮我吗。。提前感谢。使用
mysql\u fetch\u assoc()
从数据库中获取关联数组,因为您只得到一个结果:
<?php
mysql_select_db("theatdb", $con);
$result = mysql_query("SELECT Lat,Lon FROM theaters WHERE theater_name='theater_name'");
$row = mysql_fetch_assoc($result);
echo $row['theater_name'];
?>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(<?php echo $row['Lat'];?>,<?php echo $row['Lon'];?>);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
}
</script>
让我知道这是你想要得到的还是你指的其他东西
var lat = <?php echo $result['lat'] ?>;
var lang = <?php echo $result['lang'] ?>;
var latlng = new google.maps.LatLng(lat,lang);
var-lat=;
var lang=;
var latlng=新的google.maps.latlng(lat,lang);
请停止使用mysql\uuu
函数,它们已被弃用。告诉他不是我,我更正了他的代码。他是否可以选择转会到PDO
var lat = <?php echo $result['lat'] ?>;
var lang = <?php echo $result['lang'] ?>;
var latlng = new google.maps.LatLng(lat,lang);