Jump to content

Map Markers Do Not Show


phdphd

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;">
<?php
$outputcoord = implode(",", $coordinates);
echo htmlspecialchars($outputcoord);
?>
</div>
<script>
var div = document.getElementById("dom-target-coord");
var myDataCoord = div.textContent;
</script>
<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 ?

Thanks!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.