未捕获的错误:无效的LatLng对象:(未定义,未定义)

时间:2017-08-24 08:15:03

标签: javascript php leaflet

我的传单地图有问题。我正试图向地图显示所有标记,但似乎它不想在我的网站上工作,但在本地服务器(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;
    }

我不知道会出现什么问题......有什么想法吗?它可以帮助我很多..我是一个菜鸟

1 个答案:

答案 0 :(得分:0)

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