2017-08-12 8 views
-1

GoogleからMySQLとPHPでGoogleマップを実装するチュートリアルに従っています。ここに私のコードは次のとおりです。Googleマップを使用しているときにコンソールでエラーが発生する:Uncaught ReferenceError:アイコンが定義されていません

<div class="container"> 
    <div id="map"> 

    </div> 
</div> 
<script> 
function initMap() { 
    var map = new google.maps.Map(document.getElementById('map'), { 
     center: new google.maps.LatLng(XX.XXX, XX.XXX), 
     zoom: 12 
    }); 
    var infoWindow = new google.maps.InfoWindow; 

     // Change this depending on the name of your PHP or XML file 
     downloadUrl('http://xxxxxx.com/xxxxxxxx.php/', function(data) { 
     var xml = data.responseXML; 
     var markers = xml.documentElement.getElementsByTagName('marker'); 
     Array.prototype.forEach.call(markers, function(markerElem) { 
      var id = markerElem.getAttribute('id'); 

      var point = new google.maps.LatLng(
       parseFloat(markerElem.getAttribute('lat')), 
       parseFloat(markerElem.getAttribute('lng'))); 

      var infowincontent = document.createElement('div'); 
      var strong = document.createElement('strong'); 
      strong.textContent = id 
      infowincontent.appendChild(strong); 
      infowincontent.appendChild(document.createElement('br')); 

      var marker = new google.maps.Marker({ 
      map: map, 
      position: point, 
      label: icon.label 
      }); 
      marker.addListener('click', function() { 
      infoWindow.setContent(infowincontent); 
      infoWindow.open(map, marker); 
      }); 
     }); 
     }); 
    } 



    function downloadUrl(url, callback) { 
    var request = window.ActiveXObject ? 
     new ActiveXObject('Microsoft.XMLHTTP') : 
     new XMLHttpRequest; 

    request.onreadystatechange = function() { 
     if (request.readyState == 4) { 
     request.onreadystatechange = doNothing; 
     callback(request, request.status); 
     } 
    }; 

    request.open('GET', url, true); 
    request.send(null); 
    } 

    function doNothing() {} 
</script> 
<script async defer 
src="https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXX&callback=initMap"> 
</script> 

私は成功したXMLデータを作成し、私はdownloadUrl機能でデータという呼び出すPHPスクリプトを作成するためのポイントを介してチュートリアルに従ってきました。しかし、チュートリアルは静的なXMLファイルの使用に基づいています。地図上にマーカーが表示されるように変更する必要があると思います。

キャッチされないにReferenceError::私は私のページ上でコンソールを開くと、イムは、次のエラーを取得HTMLCollection.forEachで57

()

:アイコンがprofile.phpで

が定義されていません。 profile.phpで:XMLHttpRequest.request.onreadystatechange(profile.php:77)で41

トンを解決する方法上の任意のアイデアheseエラー?私は何時間もこれに固執してきた。前もって感謝します!

+0

'icon'変数が定義されていません(それはあなたが開始した、Googleの例にあるとき) – geocodezip

答えて

0

コードにiconが定義されていません。変更:

var marker = new google.maps.Marker({ 
    map: map, 
    position: point, 
    label: icon.label 
    }); 

へ:

var marker = new google.maps.Marker({ 
    map: map, 
    position: point 
    }); 
関連する問題