我正在尝试创建一个显示信息(存放位置和所存放物料的重量)的Google Maps地图。它仅显示一个标记,而不显示多个。我认为问题是数据分配给变量$ users_dump_map,但我不具备解决问题的知识。我该怎么办?
PHP
<?php
$db_name = 'db.db';
$db_drvr = 'sqlite';
$user_info = Array();
$user_dumps = Array();
$containers = Array();
$users_dumps_map = Array();
try{
$pdo = new PDO("$db_drvr:$db_name");
$ui_query = $pdo->prepare('SELECT * FROM users WHERE id = :user_id');
$ui_query->bindParam(':user_id', $_POST['user_id'], PDO::PARAM_INT);
$ui_query->execute();
$user_info = $ui_query->fetch(PDO::FETCH_ASSOC);
$ud_query = $pdo->prepare('SELECT * FROM garbage WHERE user_id = :user_id');
$ud_query->bindParam(':user_id', $_POST['user_id'], PDO::PARAM_INT);
$ud_query->execute();
$user_dumps = $ud_query->fetchAll(PDO::FETCH_ASSOC);
$c_query = $pdo->prepare('SELECT * FROM containers');
$c_query->execute();
$c_results = $c_query->fetchAll(PDO::FETCH_ASSOC);
foreach( $c_results as $dump ){
$containers[$dump['id']] = $dump['location'];
$users_dumps_map[$dump['id']] = $dump['coord'];
}
}
catch(PDOException $e){
var_dump($e);
$user_info = Array();
$user_dumps = Array();
$users_dumps_map = Array();
}
?>
GOOGLE地图
echo' <script>
function myMap() {
var myCenter = new google.maps.LatLng('.$users_dumps_map[$dump['container_id']].');
var mapCanvas = document.getElementById("map");
var mapOptions = {
center: myCenter,
zoom: 5
};
var map = new google.maps.Map(mapCanvas, mapOptions);
var marker = new google.maps.Marker({
position: myCenter
});
marker.setMap(map);
var infowindow = new google.maps.InfoWindow({
content: "'.$dump['quantity'].'"
});
infowindow.open(map, marker);
}
</script>';
asfasdf