I am trying to include a google map in my php file. I have it set up and when I run it, the map works perfectly with no errors, but when I include it in my php file, nothing comes up, no errors, just blank.
I have tried using require, include and include_once, and even just putting all the contents of my map file into my php file rather than including it, none of these work. I am getting no errors so I am unsure of why this is happening.
<?php include_once '../google_map.php';?>
I expect my google map to display along with other contents in my php file. I didnt post the code for my map as it works fine on its own, just not in an include, please let me know if I should post it.
New: This is the google_map.php
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 50%;
width: 40%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map;
function initMap()
{
map = new google.maps.Map(document.getElementById('map'),
{
center: {lat: -34.397, lng: 150.644}, zoom: 8 }); } initMap(); </script>
<script src="https://maps.googleapis.com/maps/api/js?key=MYKEY&callback=initMap"
async defer></script>
</body>
</html>
and this is how I am including it:
<?php
if ((include '../google_map.php') == TRUE) {
echo 'OK';
}
?>
When google_map.php is run itself, it works and shows the map. When i use include in a different php file, it does not work, and I only get 'OK' in which OK comes from the code above