내가 MySQL의 DB에서 위도 긴 값을 가져오고지도에 표시 위치 마커 구글 맵에 그 값을 전달하려고해야
하지만, 현재 나는 마지막 행 데이터 만 가져 왔으므로 마커 하나만 나타냅니다. 지도의 모든 위치를 표시하는 방법 ??
<?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>
현재 마지막 위도 기록을 가져 오는 하나 개의 마커 즉를 표시하고 긴 방법 LAT MySQL을 사용지도, long 값의 모든 장소를 표시하는지도 에 지정?
"마지막 행"이란 'ORDER BY datetime DESC LIMIT 10'과 같은 것을 의미합니까? –
에는 위도와 경도 값이 있으며 그 위치는 다른 장소와 같은 하나 이상의 레코드이며이 위도와 경도 값을 사용하여지도에 표시 위치가 있습니다 .....이 코드를 사용하면 단 하나의 장소 만 표시 할 수 있습니다. .. 그래서지도의 모든 장소를 어떻게 표시해야 하느냐? –