Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
add comment (requires an account with 50 reputation)

3 Answers

up vote 2 down vote accepted

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

<?php print json_encode($date) ?>
share|improve this answer
add comment (requires an account with 50 reputation)

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

var myGeolocatedItems = <?= $sJsonEncodedArray; ?>; 
share|improve this answer
add comment (requires an account with 50 reputation)
 var simple ='<?php echo $sparam1; ?>';

you can assign any php variable using the above way

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.