gpt4 book ai didi

php - 将数据库中的数据转换为列表

转载 作者:行者123 更新时间:2023-11-28 02:10:36 25 4
gpt4 key购买 nike

我想从我的数据库中检索纬度和经度,并在 Google map 上将它们显示为制造商。我是从Google Maps JS API v3 - Simple Multiple Marker Example学到的。但在本例中,纬度和经度是由用户指定的。我想知道我是否已经从数据库中检索了我的纬度和经度,例如在 php 中,$lat $long,如何将它们分配到这样的列表中:

var locations=[[..,..],[..,..],[..,..]]
//$lat is the first parameter and $long is the second.

非常感谢!

最佳答案

这里有一些伪代码,应该可以帮助您实现自己的目的。

$results = array();
while($row = $query->getResult()){
$results[] = array($row["place_name"],
$row["latitude"],
$row["longitude"],
$row["id"]);

}
?>
var locations = <?= json_encode($results); ?>;

关于php - 将数据库中的数据转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17140778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com