I put lat on the row[2] and put lng on the row[3] in my DB when I run the code below, the Google map is not visible. However, when I change variables like latitude = 25.3444 longitude = 131.0369 it works
I want to know what the problem is with the code below.
<?php
while($row = mysqli_fetch_array($result)){
if($row[0] == $num){
$lat = $row[2];
$lng = $row[3];
}
}
?>
<script>
latitude = '<?= $lat ?>';
longitude = '<?= $lng ?>';
function initMap() {
var uluru = {lat: latitude, lng: longtitude};
var map = new google.maps.Map(
document.getElementById('map'), {zoom: 7, center: uluru});
var marker = new google.maps.Marker({position: uluru, map: map});
}
</script>
define $lat
and lng
before while
<?php
var $lat = '';
var $lng = '';
while($row = mysqli_fetch_array($result)){
if($row[0] == $num){
$lat = $row[2];
$lng = $row[3];
}
}
?>
<script>
latitude = '<?= $lat ?>';
longitude = '<?= $lng ?>';
you only have to define the lat and lng to set those variables: In php:
$lat = what ever you want;
$lng = what ever you want;
In js:
let lat = what ever you want;
let lng = what ever you want;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.