[Solved] loading a map by lat and lang stored in a database


You have two errors in the code you have provided. First, you have to say

<?php echo $position['lat']; ?>

not

<?php $position['lat']; ?>

Second, instead of taking the default values for lat and lng inside the php loop, initialize the variables at the time you declare them. So the code you need will look something like:

 var map;
   var cntr = {lat: 30, lng: 70};
   var zm = 7;

   <?php if(!empty($position['lat']) && !empty($position['lang'])){ ?>
      
        var latValue = <?php echo $position['lat']; ?> ;
        var langValue = <?php echo $position['lang']; ?> ;  
     
        cntr = {lat: latValue, lng: langValue};
        zm = 8;
                                              
   <?php } ?>
     
   function initialize() {
       var mapOptions = {
            center: cntr,
            zoom: zm
       };
     
     //rest of the code

Hope this helps you.

0

solved loading a map by lat and lang stored in a database