Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                                                                                            
                
        
我的传单地图有问题。我正在尝试显示地图上的所有标记,但似乎它不想在我的网站上工作,但是在本地服务器(xampp)上却能正常工作..这是什么问题?谢谢!

<script type="text/javascript">
  function addScoala1() {
   for(var i=0; i<scoala.length; i++) {
    var greenIcon = new L.Icon({
  iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
  shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
  iconSize: [25, 41],
  iconAnchor: [12, 41],
  popupAnchor: [1, -34],
  shadowSize: [41, 41]
});
    var marker = L.marker( [scoala[i]['latitudine'], scoala[i]['longitudine']], {icon: greenIcon}).addTo(map);
    marker.bindPopup( "<b>" + scoala[i]['scoala']+"</b><br>Detalii:" + scoala[i]['detalii'] + "<br />Telefon: " + scoala[i]['telefon']);
   }
  }

function addMuzeu1() {
   for(var i=0; i<muzeu.length; i++) {
    var marker = L.marker( [muzeu[i]['latitudine'], muzeu[i]['longitudine']]).addTo(map);
    marker.bindPopup( "<b>" + muzeu[i]['muzeu']+"</b><br>Detalii:" + muzeu[i]['detalii'] + "<br />Telefon: " + muzeu[i]['telefon']);
   }
  }
$( document ).ready(function() {
  var map = L.map('map').setView([44.9323281,26.0306833], 12,25);

  L.tileLayer( 'https://api.mapbox.com/styles/v1/mapbox/streets-v10/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWVnYTYzODIiLCJhIjoiY2ozbXpsZHgxMDAzNjJxbndweDQ4am5mZyJ9.uHEjtQhnIuva7f6pAfrdTw', {
   maxZoom: 18,
   attribution: 'Map data &copy; <a href="http://openstreetmap.org/"> OpenStreetMap </a> contributors, ' +
    '<a href="http://creativecommons.org/"> CC-BY-SA </a>, ' +
    'Imagery © <a href="http://mapbox.com">Mapbox</a>',
   id: 'examples.map-i875mjb7'
  }).addTo(map);
  var scoala = JSON.parse('<?php echo json_encode($scoala) ?>');
  var muzeu = JSON.parse('<?php echo json_encode($muzeu) ?>');
  console.log(scoala);
 addScoala1();
 addMuzeu1();
});
</script>


变量是:

 $scoala = $conn->getScoalaList();
 $muzeu = $conn->getMuzeuList();
 $zona = $conn->getZonaList();


getScoalaList()和其他函数是:

 public function getScoalaList()
    {
          $arr = array();
          $statement = $this->aDBConn->prepare( "SELECT id, nume, detalii, latitudine, longitudine, telefon, cuv_cheie from scoala order by nume ASC");
          $statement->bind_result( $id, $scoala1, $detalii1, $latitudine1, $longitudine1, $telefon1, $cuv_cheie1);
          $statement->execute();
          while ($statement->fetch()) {
            $arr = array('id' => $id, 'scoala' => $scoala1, 'detalii' => $detalii1, 'latitudine' => $latitudine1, 'longitudine' => $longitudine1, 'telefon' => $telefon1, 'cuv_cheie' => $cuv_cheie1);
          }
          $statement->close();

          return $arr;
    }
        public function getMuzeuList()
    {
          $arr = array();
          $statement = $this->aDBConn->prepare( "SELECT id, nume, detalii, latitudine, longitudine, telefon, cuv_cheie from muzeu order by nume ASC");
          $statement->bind_result( $id, $muzeu, $detalii, $latitudine1, $longitudine1, $telefon, $cuv_cheie);
          $statement->execute();
          while ($statement->fetch()) {
            $arr =array('id' => $id, 'muzeu' => $muzeu, 'detalii' => $detalii, 'latitudine' => $latitudine1, 'longitudine' => $longitudine1, 'telefon' => $telefon, 'cuv_cheie' => $cuv_cheie);
          }
          $statement->close();

          return $arr;
    }


我不知道这可能是什么问题...有什么想法吗?它可以帮助我很多..我是菜鸟

最佳答案

解决了该问题,我应该将addScoala1()和其他函数添加到document.ready()函数中。

关于javascript - 未捕获的错误:无效的LatLng对象:(未定义,未定义),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45856357/

10-14 14:39