데이터베이스에서 Google지도 정보를 채우는 데 문제가 있습니다. 내가 가지고있는 개념은 다음과 같습니다 : 경도와 위도와 같은 마커 정보로 채워진 데이터베이스와 해당 정보로 채워진 다른 테이블. 마커가있는지도를 채울 수 있었지만 정보 창에 정확한 정보를 채우는 것은 이미 2 일 동안 고생하고있는 것입니다.데이터베이스에서 Google지도 정보 창 채우기
내가 사용하는 코드는 다음과 같다 :
<html>
<head>
<?php
$con = mysqli_connect("localhost","root","","unwdmi");
$result = mysqli_query($con,"SELECT stationNummer ,longitude, latitude FROM stations");
$i = 0;
$array = array();
$array2 = array();
$array3 = array();
while ($heg = mysqli_fetch_array($result)){
$array[$i] = $heg['longitude'];
$array1[$i] = $heg['latitude'];
$array2[$i] = $heg['stationNummer'];
$i++;
}
$i = 0;
?>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src=
"http://maps.googleapis.com/maps/api/js?key=AIzaSyB1tbIAqN0XqcgTR1- FxYoVTVq6Is6lD98&sensor=false">
</script>
<script type="text/javascript">
var infos = [];
var locations = [ <?php
foreach($array as $value) {
$longitude = $value;
$latitude = $array1[$i];
$stationNummer = $array2[$i];
$test = "'loan', $latitude, $longitude, 'address $i'"; ?> [ <?php echo $test; ?> ], <?php
$i++;
} ?>
];
$.ajax({
url: 'ajax.php', //This is the current doc
type: "POST",
dataType: 'json', // add json datatype to get json
data: ({
stationNummer: 10015
}),
success: function(data) {
console.log(data);
}
});
function initialize() {
var myOptions = {
center: new google.maps.LatLng(33.890542, 151.274856),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("default"),
myOptions);
setMarkers(map, locations)
}
function setMarkers(map, locations) {
var marker, i
for (i = 0; i < locations.length; i++) {
var loan = locations[i][0]
var lat = locations[i][1]
var long = locations[i][2]
var add = locations[i][3]
jQuery.ajax({
url: 'ajax.php', //This is the current doc
type: "POST",
dataType: 'json', // add json datatype to get json
data: ({
loan
}),
success: function(data) {
console.log(data);
}
});
latlngset = new google.maps.LatLng(lat, long);
var marker = new google.maps.Marker({
map: map,
title: loan,
position: latlngset
});
map.setCenter(marker.getPosition())
var content = data;
var infowindow = new google.maps.InfoWindow()
google.maps.event.addListener(marker, 'click', (function(marker, content, infowindow) {
return function() {
/* close the previous info-window */
closeInfos();
infowindow.setContent(content);
infowindow.open(map, marker);
/* keep the handle, in order to close it on next click event */
infos[0] = infowindow;
};
})(marker, content, infowindow));
}
}
function closeInfos() {
if (infos.length > 0) {
/* detach the info-window from the marker ... undocumented in the API docs */
infos[0].set("marker", null);
/* and close it */
infos[0].close();
/* blank the array */
infos.length = 0;
}
}
</script>
</head>
<body onload="initialize()">
<div id="default" style="width:100%; height:100%"></div>
</body>
</html>
</script>
</head>
<body onload="initialize()">
<div id="default" style="width:100%; height:100%"></div>
</body>
</html>
내가 이쪽을 참고로하는 것에하고있어 PHP 파일 :
<?php
$userAnswer = $_POST['loan'];
$con = mysqli_connect("localhost","root","","unwdmi");
$result = mysqli_query($con,"SELECT temp, prcp, wdsp, cldc FROM measurement WHERE stationNummer =".$userAnswer."");
while ($heg1 = mysqli_fetch_array($result)){
$temp = $heg1['temp'];
$prcp = $heg1['prcp'];
$wdsp = $heg1['wdsp'];
$cldc = $heg1['cldc'];
}
$text = "<table border='4'>
<tr>
<th>Temperatuur</th>
<th>Neerslag</th>
<th>Windsnelheid</th>
<th>Bewolkingsgraad</th>
</tr>
<tr>
<td>".$temp."</td>
<td>".$prcp."</td>
<td>".$wdsp."</td>
<td>".$cldc."</td>
</tr>";
echo json_encode($text);
?>
누군가가이 문제를 도와 줄 수 있기를 바랍니다.
여기에서 접근 방식을 완전히 다시 생각해야합니다. 경도, 위도 및 스테이션 번호에 대해 $ array1, $ array2라는 쓸데없는 이름의 $ 배열 인 모든 데이터에 대해 3 개의 PHP 배열이 있습니다. 그 대신에 $ locations [$ i] = [ \t '위도'=> $ heg [ '위도'], \t '경도'=> $ heg [ '경도' ], \t 'stationNummer'=> $ heg [ 'stationNummer'] ]; 그러면 JS로 변환하려고 할 때 삶이 약간 쉬워 질 수 있습니다. – duncan