2016-03-25 2 views
-1

Ich arbeite mit Google Map API, ich separate Datenbank (mysql) pflegen, die Standort enthält (Adresse & latlng), wenn ich einen einzelnen Standort anrufen, funktioniert es, aber wenn Es gibt mehr als einen Ort, um einen Marker auf die Karte zu setzen, sagt das Google Dev Tool uncaught Range error: maximum call stack size exceeded. Ich habe alle Quellen im Interweb ausprobiert, alle Ergebnisse sind negativ.Bereich Fehler: maximale Call-Stack-Größe in Google Karte überschritten api

$(document).ready(function(){ 
      $("#searchbutton").click(function(){ 
       var category = document.getElementById("categoryinput").value; 
       var place = document.getElementById("placeinput").value; 
       $("#mapcontainer").css("display","block"); 
       $.get("http://localhost:80/rule/search.php?category="+category+"&place="+place, function(data){ 
        $("#hiddeninput").val(data); 
        //Initialize the Google Maps 
        var geocoder; 
        var map; 
        var markersArray = []; 
        var infos = []; 
        geocoder = new google.maps.Geocoder(); 
        var myOptions = { 
          mapTypeId: google.maps.MapTypeId.ROADMAP, 
          zoom: 9 
         }; 
        //Load the Map into the map_canvas div 
        var map = new google.maps.Map(document.getElementById("mapcontainer"), myOptions); 
        map = new google.maps.Map(document.getElementById("mapcontainer"), myOptions); 

        //Initialize a variable that the auto-size the map to whatever you are plotting 
        var bounds = new google.maps.LatLngBounds(); 
        //Initialize the encoded string  
        var encodedString; 
        //Initialize the array that will hold the contents of the split string 
        var stringArray = []; 
        //Get the value of the encoded string from the hidden input 
        encodedString = document.getElementById("hiddeninput").value; 
        //Split the encoded string into an array the separates each location 
        stringArray = encodedString.split("****"); 

        var x; 
        for (x = 0; x < stringArray.length; x = x + 1) 
        { 
         var addressDetails = []; 
         var markericon = 'img/mapmarker.png'; 
         var marker; 
         //Separate each field 
         addressDetails = stringArray[x].split("&&&"); 
         //Load the lat, long data 
         var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]); 
         //Create a new marker and info window 
         marker = new google.maps.Marker({ 
          map: map, 
          position: lat, 
          animation: google.maps.Animation.DROP, 
          //Content is what will show up in the info window 
          content: addressDetails[0], 
          icon: markericon 
         }); 
         //Pushing the markers into an array so that it's easier to manage them 
         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; 
         } 
        } 
       }); 
      }); 
     }); 

dieser Code sendet die jQuery-Ajax-Request

<?php 

header('Access-Control-Allow-Origin:*'); 

//create connection to database MYSQL 

mysql_connect('localhost','root',''); 
mysql_select_db('locations') or exit('no db found'); 

$category = $_GET['category']; 
$place = $_GET['place']; 



if(empty($category) && empty($place)){ 
    echo "invalid input"; 
} 
else{ 

    $searchquery ="SELECT * FROM `locationDatabase` WHERE `category`='$category'and `nagar`='$place' or `area`='$place'"; 
    $searchqueryexecute = mysql_query($searchquery); 
    while($rows = mysql_fetch_assoc($searchqueryexecute)) { 
     # code... 

     $encodedstring = ""; 
     $x = 0; 


     if($x == 0){ 
      $seperator = ""; 
     } 
     else{ 
      $seperator = "****"; 
     } 
     $encodedstring = $encodedstring.$seperator. 
     "<p class='info'><b>".$rows['name']. 
     "</b><br><b>".$rows['door_no']. 
     "</b><br><b>".$rows['street']. 
     "</b><br><b>".$rows['nagar']. 
     "</b><br><b>".$rows['area']. 
     "</b><br><b>".$rows['city']."-".$rows['zipcode']. 
     "</b></p>&&&".$rows['latitude']."&&&".$rows['longitude']; 
     $x = $x + 1; 

     echo $encodedstring;  
    } 

} 

?> 
+0

Wie sehen Ihre Daten aussehen für mehrere Punkte? – geocodezip

+0

Der veröffentlichte Code zeigt den gemeldeten Fehler nicht (zumindest wenn ich die erwarteten Daten bereitstelle) – geocodezip

+0

Der Fehler sagt alles. Sie haben entweder einen Fehler, der eine Endlosschleife erzeugt, die viele Funktionen aufruft, die schließlich einen Stapelüberlauf erzeugen, oder Ihre Daten sind zu groß, was das Gleiche verursacht. Im ersten Fall, behebe den Fehler und mach weiter. Versuchen Sie, den Code neu zu schreiben, indem Sie setTimeout aufrufen, damit die Aufrufe von der Ereignisschleife ausgelöst werden. – Will

Antwort

0

Ihr Code wird eine zusätzliche "****" bis zum Ende der Datenkette angehängt wird. Dadurch wird ein zusätzlicher leerer Punkt zur Karte hinzugefügt, wodurch die Grenzen ungültig werden. Fügen Sie entweder eine Fehlerprüfung hinzu, bevor Sie den Hersteller erstellen:

Oder entfernen Sie das zusätzliche "****" vom Ende der Daten.

Sieht aus wie Ihr PHP sein sollte (nur die Zeichenfolge mit dem Ausgang Echo, wenn es abgeschlossen ist):

$encodedstring = ""; 
$x = 0; 
while($rows = mysql_fetch_assoc($searchqueryexecute)) { 
    # code... 

    if($x == 0){ 
     $seperator = ""; 
    } 
    else{ 
     $seperator = "****"; 
    } 
    $encodedstring = $encodedstring.$seperator. 
    "<p class='info'><b>".$rows['name']. 
    "</b><br><b>".$rows['door_no']. 
    "</b><br><b>".$rows['street']. 
    "</b><br><b>".$rows['nagar']. 
    "</b><br><b>".$rows['area']. 
    "</b><br><b>".$rows['city']."-".$rows['zipcode']. 
    "</b></p>&&&".$rows['latitude']."&&&".$rows['longitude']; 
    $x = $x + 1; 

} 
echo $encodedstring; 
Verwandte Themen