Getting php variables into javascript
Posted: Wed Feb 22, 2017 12:32 am
I am using the Google Map API and am trying to capture URL arguments into the JavaScript for the map.
Here is my URL including the arguments:
http://www.beleuramyhome.org.au/myvilla ... lvilla=177
Here is my actual code (which doesn't work) = the result you see through the above link is hard coded at the moment.
The PHP part of retrieving the URL arguments works fine, but the assignment into the JS variables doesn't work... Why?
<?php
$phplat = "<?php echo $_GET["urllong"]?>";
$phplong = "<?php echo $_GET["urllong"]?>";
$phpvilla = "<?php echo $_GET["urlvilla"]?>";
?>
<script type="text/javascript">
var map;
var mylat = $phplat;
var mylong = $phplong;
var myvilla = $phpvilla;
function initMap()
{
var myLatLng = {lat: mylat, lng: mylong};
map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
zoom: 18,mapTypeId: 'satellite'
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: myvilla
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js ... ck=initMap"
async defer></script>
Here is my URL including the arguments:
http://www.beleuramyhome.org.au/myvilla ... lvilla=177
Here is my actual code (which doesn't work) = the result you see through the above link is hard coded at the moment.
The PHP part of retrieving the URL arguments works fine, but the assignment into the JS variables doesn't work... Why?
<?php
$phplat = "<?php echo $_GET["urllong"]?>";
$phplong = "<?php echo $_GET["urllong"]?>";
$phpvilla = "<?php echo $_GET["urlvilla"]?>";
?>
<script type="text/javascript">
var map;
var mylat = $phplat;
var mylong = $phplong;
var myvilla = $phpvilla;
function initMap()
{
var myLatLng = {lat: mylat, lng: mylong};
map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
zoom: 18,mapTypeId: 'satellite'
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: myvilla
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js ... ck=initMap"
async defer></script>