1

I want to retrieve latitude and longitude from my database and show them as maker on Google Map. I learned it from Google Maps JS API v3 - Simple Multiple Marker Example. But in this example, the latitude and longitude is assigned by user. I want to know if I have already retrieved my lat&long from my database, for example in php, $lat $long, how to assign them into a list like this:

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

Many thanks!

4

3 回答 3

1

这是一个小伪代码,应该可以让您按照自己的方式行事。

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

}
?>
var locations = <?= json_encode($results); ?>;
于 2013-06-17T06:04:36.870 回答
0

您可以在 php 中存储多维数组。这是示例链接

这是你想要的?

于 2013-06-17T05:14:11.327 回答
0

我认为您只需回应现有的价值观,如下所示:

var locations = [<?php
    for ($i = 0; $i < count($lat); $i++) {
        if ($i > 0) echo ",";
        echo "[" . $lat[$i] . "],[" . $long[$i] . "]";
    }
?>];
于 2013-06-17T05:28:40.827 回答