Jump to content

Map Markers Do Not Show


Recommended Posts

Hi All,

I have a php file with some JS that implements a map with markers on it. It works. However to make my php file cleaner, I want to move the JS that builds the map and markers to a seperate js file.

In the initial PHP file, the JS code has a line like this for the coordinates, that I need to adapt for a standalone JS file.

var addressPoints = [<?php echo implode(",", $coordinates); ?>];


So I created a hidden div to echo the coordinates before storing them into a JS variable. I did the following :

<div id="dom-target-coord" style="display: none;">
$outputcoord = implode(",", $coordinates);
echo htmlspecialchars($outputcoord);
var div = document.getElementById("dom-target-coord");
var myDataCoord = div.textContent;
<script src="../js/map.js"></script>


And the first line of the map.js file is

var addressPoints = [myDataCoord];

This does not work. In there something wrong in the syntax of this line ?


Link to comment
Share on other sites

Think about how it works. Your original form will create output that looks like [1, 2, 3, ...] which is an array with however-many elements. The new form is [variable] which is an array with one element, whose value is a string.

[1, 2, 3] versus ["1, 2, 3"].

But what you have now really isn't the way to go about it. You say you wanted to move the map stuff to another file? How so?

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.