When I view JSON data as an alert when the page loads, I see:
[
"Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery",
37.69603499999999,
-79.17580859999998,
"<div id=\"post-45\"><a href=\"http://localhost/jhtwp/business/ankida-ridge-vineyards-the-vrooman-family-vineyard-winery/\">Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery</a></div>"
]
which passes on JSONlint. In my source data however, I see this:
/* <![CDATA[ */
var busipress_map_vars = [];
busipress_map_vars = {"default_map_icon":"http:\/\/localhost\/jhtwp\/wp-content\/plugins\/busipress\/img\/red-dot.png","default_map_icon_width":32,"default_map_icon_height":32,"active_map_icon":"http:\/\/localhost\/jhtwp\/wp-content\/plugins\/busipress\/img\/blue-dot.png","active_map_icon_width":32,"active_map_icon_height":32,"map_icon_shadow":"http:\/\/localhost\/jhtwp\/wp-content\/plugins\/busipress\/img\/msmarker.shadow.png","map_icon_shadow_width":59,"map_icon_shadow_height":32,"center_lat":-34.397,"center_long":150.644,"path_start":"35.7719444, -78.6388889","path_end":"32.7763889, -79.9311111","locations":"[\"Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery\",37.69603499999999, -79.17580859999998, \"<div id=\\\"post-45\\\"><a href=\\\"http:\/\/localhost\/jhtwp\/business\/ankida-ridge-vineyards-the-vrooman-family-vineyard-winery\/\\\">Ankida Ridge Vineyards – The Vrooman Family Vineyard & Winery<\/a><\/div>\"]"};;
/* ]]> */
</script>
which is escaping the double-quotes (there’s some other data in there that works fine). I have the following function that generates each location:
function busipress_business_teaser($echo = true, $zindex) {
$location = get_field('address');
$location_array = explode(',',$location['coordinates']);
ob_start();
echo '["';
echo get_the_title();
echo '",';
echo $location_array[0] . ', ';
echo $location_array[1] . ', ';
echo '"<div ';
echo 'id=\"post-'.get_the_ID().'\">';
echo '<a href=\"'.get_permalink().'\">';
echo get_the_title();
echo '</a>';
echo '</div>"';
echo ']';
$display = ob_get_contents();
ob_end_clean();
if($echo) {
echo $display;
}
else {
return $display;
}
}
am I creating this data the wrong way? Using this withe Google Maps API v3. Thanks!
I think your function should look like this
If you want to work with Goolge MAP they are enough PHP class to do just that