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!

Community
  • 1
  • 1
user2462090
  • 119
  • 1
  • 1
  • 12

3 Answers3

1

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); ?>;
Orangepill
  • 24,500
  • 3
  • 42
  • 63
0

you can store multidimensional arrays in php. Here is the example link.

Is this what you are looking for?

voidMainReturn
  • 3,339
  • 6
  • 38
  • 66
0

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] . "]";
    }
?>];
uber5001
  • 3,864
  • 4
  • 23
  • 44