I am having some trouble casting a PHP variable to JS. I need to get Lat and Long for a google map, however it will not work with the following code:
PHP (Wordpress):
$lat = get_post_meta( $post->ID, 'lat', true );
$long = get_post_meta( $post->ID, 'long', true );
The Script:
<script type="text/javascript>
var LatVar = '<?php echo $lat; ?>';
var LngVar = '<?php echo $long; ?>';
var myLatLng = {lat: LatVar, lng: LngVar};
</script>
If i insert the Lat and Long manually the map works. I have tested that the PHP get the variables correctly, since when using echo $lat or print_r($lat)` i get the correct data e.g. 9.916599
error_reporting();Additionally, what do you get withconsole.log(LatVar);in JavaScript?