<?
php
//error: Google Maps JavaScript API error: ApiNotActivatedMapError
//solution: click "APIs and services" Link
// click "Enable APIs and services" button
// Select "Maps JavaScript API" then click on enable
require '[Link]';
$sql = "SELECT * FROM tbl_gps WHERE 1";
$result = $db->query($sql);
if (!$result) {
{ echo "Error: " . $sql . "<br>" . $db->error; }
}
$rows = $result -> fetch_all(MYSQLI_ASSOC);
//print_r($row);
//header('Content-Type: application/json');
//echo json_encode($rows);
?>
<html>
<head>
<title>Add Markers to Show Locations in Google Maps</title>
</head>
<style>
body {
font-family: Arial;
}
#map-layer {
margin: 20px 0px;
max-width: 700px;
min-height: 400;
}
</style>
<body>
<h1>Add Markers to Show Locations in Google Maps</h1>
<div id="map-layer"></div>
<script
src="[Link]
key=ENTER_API_KEY&callback=initMap"
async defer></script>
<script>
var map;
function initMap() {
var mapLayer = [Link]("map-layer");
var centerCoordinates = new [Link](-33.890541,
151.274857);
var defaultOptions = { center: centerCoordinates, zoom: 10 }
map = new [Link](mapLayer, defaultOptions);
<?php foreach($rows as $location){ ?>
var location = new [Link](<?php echo
$location['lat']; ?>, <?php echo $location['lng']; ?>);
var marker = new [Link]({
position: location,
map: map
});
<?php } ?>
}
</script>
</body>
</html>