-1
<!DOCTYPE html>
<?php
/* lat/lng data will be added to this array */
try{$work=$_GET["service"];}catch(Exception $e){echo 'Authorization Failed.Map may Misbehave or Buggy.<a href="submitbug.php">Click here to report this</a>';}
$locations=array();
$uname="root";
$pass="";
$servername="localhost";
$dbname="bcremote";
$db=new mysqli($servername,$uname,$pass,$dbname);
$query = $db->query('SELECT * FROM location');
while($row = $query->fetch_assoc()){
$name = $row['uname'];
$longitude = $row['longitude'];
$latitude = $row['latitude'];
$link=$row['link'];
/* Each row is added as a new array */
$locations[]=array('name'=>$name, 'lat'=>$latitude, 'lng'=>$longitude, 'lnk'=>$link);
}
//echo $locations[0]['name'].": In stock: ".$locations[0]['lat'].", sold: ".$locations[0]['lng'].".<br>";
//echo $locations[1]['name'].": In stock: ".$locations[1]['lat'].", sold: ".$locations[1]['lng'].".<br>";
?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAfFN8NuvYyNkewBVMsk9ZNIcUWDEqHg2U&callback=initMap()"
async defer></script>
<script>
//var myLatLng = {lat: -25.363, lng: 131.044};
function initMap() {
var myLatLng = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
scrollwheel: false,
zoom: 10
});
<?php for($i=0;$i<sizeof($locations);$i++)
{ ?>
var marker = new google.maps.Marker({
map: map,
position: {lat: <?php echo $locations[$i]['lat']?>,lng: <?php echo $locations[$i]['lng']?>},
title: 'Service',
url: 'https://<?php echo $locations[$i]['lnk']?>'
});
google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
<?php } ?>
}
</script>
<body>
<div id="map"></div>
</body>
我有這樣的代碼。我認爲在代碼方面沒有任何錯誤可能在邏輯方面。請幫我過來這個。我需要在接下來的2天內提交這個項目。我可以知道如何解決這個問題嗎?谷歌地圖API不工作
憑藉先進的感謝, Kavin
什麼問題?請提供一個證明你的問題的[mcve]。 – geocodezip
對不起現在我已經修復了... –