I want to pass variable to google map script from php or html. but this is not working.
<?php
$x1=58.983991;
$y1=5.734863;
?>
<script>
var myCenter=new google.maps.LatLng($x1,$y1);
</script>
I want to pass variable to google map script from php or html. but this is not working.
<?php
$x1=58.983991;
$y1=5.734863;
?>
<script>
var myCenter=new google.maps.LatLng($x1,$y1);
</script>
Do it like this:
var myCenter=new google.maps.LatLng(<?php echo $x1; ?>,<?php echo $y1; ?>);
You can open PHP anywhere on the webpage until and unless the extension of the page is .php
.
<?php
$x1=58.983991;
$y1=5.734863;
?>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
var myCenter=new google.maps.LatLng(<?php echo $x1?>,<?php echo $y1?>);
</script>
Use echo Short tag of php to print values .
<?php
$x1=58.983991;
$y1=5.734863;
?>
<script>
var myCenter=new google.maps.LatLng(<?=$x1; ?>,<?=$y1;?>);
</script>