0

I have a PHP array (of arrays) of address date like this:

$date[0][lat] = 42.54
$date[0][lng] = -80.54
$date[0][title] = Business Name


$date[1][lat] = 41.54
$date[1][lng] = -81.54
$date[1][title] = Another Name

etc.

Is it possible to somehow pass this array of arrays to the google maps api to map as markers? Everything I seem to find online is either working with XML or working with data that is already a javascript array.

3 Answers 3

2

if you use PHP 5.2 or later, you can pass your array as follow

<?php print json_encode($date) ?>
Sign up to request clarification or add additional context in comments.

Comments

2

Try to encode it as json ans then just simply echo into the JS variable:

var myGeolocatedItems = <?= $sJsonEncodedArray; ?>; 

Comments

1
 var simple ='<?php echo $sparam1; ?>';

you can assign any php variable using the above way

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.