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!
Here is a little pseudo code that should get you are your way.
$results = array();
while($row = $query->getResult()){
$results[] = array($row["place_name"],
$row["latitude"],
$row["longitude"],
$row["id"]);
}
?>
var locations = <?= json_encode($results); ?>;
you can store multidimensional arrays in php. Here is the example link .
Is this what you are looking for?
I think you'd just echo the values in place, like so:
var locations = [<?php
for ($i = 0; $i < count($lat); $i++) {
if ($i > 0) echo ",";
echo "[" . $lat[$i] . "],[" . $long[$i] . "]";
}
?>];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.