2016-08-05 6 views
2
<script type='text/javascript'> 
    jQuery(document).ready(function($){ 
     var geocoder; 
     var map; 
     var markersArray = []; 
     var infos = []; 

     geocoder = new google.maps.Geocoder(); 
     var myOptions = { 
       zoom: 9, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      } 
     var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
     map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
     var bounds = new google.maps.LatLngBounds(); 
     var encodedString; 
     var stringArray = []; 
     encodedString = document.getElementById("encodedString").value; 
     stringArray = encodedString.split("****"); 

     var x; 
     for (x = 0; x < stringArray.length; x = x + 1) 
     { 
      var addressDetails = []; 
      var marker; 
      addressDetails = stringArray[x].split("&&&"); 
      var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]); 
      marker = new google.maps.Marker({ 
       map: map, 
       position: lat, 
       //Content is what will show up in the info window 
       content: addressDetails[0] 
      }); 

      markersArray.push(marker); 
      google.maps.event.addListener(marker, 'click', function() { 
       closeInfos(); 
       var info = new google.maps.InfoWindow({content: this.content}); 
       //On click the map will load the info window 
       info.open(map,this); 
       infos[0]=info; 
      }); 
      //Extends the boundaries of the map to include this new location 
      bounds.extend(lat); 
     } 
     //Takes all the lat, longs in the bounds variable and autosizes the map 
     map.fitBounds(bounds); 

     //Manages the info windows 
     function closeInfos(){ 
     if(infos.length > 0){ 
      infos[0].set("marker",null); 
      infos[0].close(); 
      infos.length = 0; 
     } 
     } 

}); 
</script> 

</head> 
<body> 
<div id='input'> 

    <?php 
    $encodedString = ""; 
    $x = 0; 

    $result = mysql_query("SELECT * FROM `table-name`"); 
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) 
    { 
     if ($x == 0) 
     { 
      $separator = ""; 
     } 
     else 
     { 
      $separator = "****"; 
     } 
     $encodedString = $encodedString.$separator. 
     "<p class='content'><b>Lat:</b> ".$row[1]. 
     "<br><b>Long:</b> ".$row[2]. 
     "<br><b>Name: </b>".$row[3]. 
     "<br><b>Address: </b>".$row[4]. 
     "</p>&&&".$row[1]."&&&".$row[2]; 
     $x = $x + 1; 
    }   
    ?> 

    <input type="hidden" id="encodedString" name="encodedString" value="<?php echo $encodedString; ?>" /> 
</div> 
<div id="map_canvas"></div> 

내가 MySQL 데이터베이스에서 구글지도 위치에 대한 위의 코드를 사용했다.너무 많은 recurssion는

위의 코드는 위도, MySQL 데이터베이스의 Lang을 가져오고 동적으로 Google지도를 만듭니다.

too much recursion & initMap is not function라는 두 개의 오류가 있습니다 : 나는 위의 코드를 실행하면

그것은 나에게 같은 오류를했다.

누구든지 나를 분류 할 수 있습니까?

미리 감사드립니다.

답변

1

js 파일에 initMap을 정의하지 않았습니다. 그래서 그 오류가 발생합니다. 당신은 아마 위도와 경도는 다음과 같은 성명

var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]); 
에 유효한 숫자 값을 포함 할 경우에도 확인

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script> 

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" async defer></script> 

에 구글지도 API를 스크립트에서 콜백 부분을 제거해야