Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views3 pages

Index PHP

The document is a PHP script that retrieves GPS coordinates from a database and displays them as markers on a Google Map. It includes error handling for the Google Maps API and instructions for enabling the API if not activated. The HTML structure and JavaScript code are set up to initialize the map and place markers based on the retrieved coordinates.

Uploaded by

Nasif Tahmid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Index PHP

The document is a PHP script that retrieves GPS coordinates from a database and displays them as markers on a Google Map. It includes error handling for the Google Maps API and instructions for enabling the API if not activated. The HTML structure and JavaScript code are set up to initialize the map and place markers based on the retrieved coordinates.

Uploaded by

Nasif Tahmid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

<?

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 'config.php';

$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="https://maps.googleapis.com/maps/api/js?
key=ENTER_API_KEY&callback=initMap"
async defer></script>

<script>
var map;
function initMap() {

var mapLayer = document.getElementById("map-layer");


var centerCoordinates = new google.maps.LatLng(-33.890541,
151.274857);
var defaultOptions = { center: centerCoordinates, zoom: 10 }

map = new google.maps.Map(mapLayer, defaultOptions);

<?php foreach($rows as $location){ ?>


var location = new google.maps.LatLng(<?php echo
$location['lat']; ?>, <?php echo $location['lng']; ?>);
var marker = new google.maps.Marker({
position: location,
map: map
});
<?php } ?>

}
</script>
</body>
</html>

You might also like