私は、MySQL DBから緯度と長い値をフェッチし、地図上に表示する位置マーカーをGoogleマップ上でそれらの値を渡すために試してみる
が、現在、私は最後の行のデータしか取得していないので、マーカーを1つだけ示します。 マップ上のすべての場所を表示する方法は?
<?php
include "config.php";
$result="select * from ds_duty_history";
$a=mysqli_query($conn,$result);
// $count_row = mysqli_num_rows($a);
while ($b = mysqli_fetch_array($a)) {
$long_d=$b['lng'];
$lat_d=$b['lat'];
$result = array(array('latitude'=>$lat_d,'longitude'=>$long_d));
}
?>
<!doctype html>
<html>
<head>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOURKEY&callback=initMap">
</script>
<script type="text/javascript">
var map;
function initialize() {
// Set static latitude, longitude value
var latlng = new google.maps.LatLng(<?php echo $lat_d; ?>, <?php echo $long_d; ?>);
// Set map options
var myOptions = {
zoom: 16,
center: latlng,
panControl: true,
zoomControl: true,
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
// Create map object with options
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
<?php
// uncomment the 2 lines below to get real data from the db
// $result = mysql_query("SELECT * FROM parkings");
// while ($row = mysql_fetch_array($result))
foreach($result as $row){ // <- remove this line
echo "addMarker(new google.maps.LatLng(".$row['latitude'].", ".$row['longitude']."), map);";}
?>
}
function addMarker(latLng, map) {
var marker = new google.maps.Marker({
position: latLng,
map: map,
draggable: true, // enables drag & drop
animation: google.maps.Animation.DROP
});
return marker;
}
</script>
</head>
<body onload="initialize()">
<div style="float:left; position:relative; width:550px; border:0px #000 solid;">
<div id="map_canvas" style="width:550px;height:400px;border:solid black 1px;"></div>
</div>
</body>
</html>
現在、唯一のマーカーすなわち、最後の緯度、レコードフェッチと長い、MySQLの緯度を使用して地図上に長い値をすべての場所を表示する方法をマップ に割り当てる表示?
「最後の行」とは、「ORDER BY datetime DESC LIMIT 10」のような意味ですか? –
のテーブルには緯度と経度の値があり、それらは異なる場所のような1つ以上のレコードであり、これらの緯度と経度の値を使用してマップ上に表示位置を持っています.....このコードを使用して、 。だから、どのように地図上のすべての場所を表示する? –