Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm trying to use PHP to add markers to Javascript (Google Maps) but it isn't working the way I have indended it
    text
    copied!<p>I'm trying to use PHP to add a custom marker using GET. I can get inside the if statement just fine and the map loads, but this doesn't add a marker, I'm not familiar with Javascript I'm just using the documentation to do what I need to do. </p> <p>Inside <code>autolocategmap.js</code> it just contains the Javascript to initialize the map and use geolocation to find the user and it works great, the only problem is the marker is not appearing on load or refresh or anything, I'm not even sure if I can append this extra bit of script by just including <code>&lt;script&gt;custom marker&lt;/script&gt;</code>, any information would be great thanks.</p> <pre><code> &lt;?php /* Include header and config and set variable*/ require_once('config.inc.php'); require_once($rootdir . $dirsubfolder . 'navbar.php'); $route = $_GET['route']; ?&gt; &lt;?php /* User wants to retrieve their route */ if ((isset($route)) &amp;&amp; (strcmp($route, "sunauto") == 0)) { ?&gt; &lt;script src="js/autolocategmap.js"&gt;&lt;/script&gt; &lt;script&gt; addMarker('56.742111','-111.481753','Stop 3', 'Arrives at: 6:00am'); &lt;/script&gt; &lt;?php } ?&gt; </code></pre> <p>autolocategmap.js:</p> <pre><code> /** * Basic Map */ $(document).ready(function(){ var map = new GMaps({ div: '#gmap', lat: 56.744901, lng: -111.473049, zoom: 16, zoomControl : true, zoomControlOpt: { style : 'SMALL', position: 'TOP_LEFT' }, panControl : false, }); GMaps.geolocate({ success: function(position) { map.setCenter(position.coords.latitude, position.coords.longitude); }, error: function(error) { alert('Geolocation failed: '+error.message); }, not_supported: function() { alert("Your browser does not support geolocation"); } }); $(window).resize(function () { var h = $(window).height(), offsetTop = 150; // Calculate the top offset $('#gmap').css('height', (h - offsetTop)); }).resize(); }); function addMarker(lat,lng,title,window){ map.addMarker({ lat: lat, lng: lng, title: title, infoWindow: window }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload