-1
私はGoogle Maps APIを使用して作業していますが、場所(アドレス& latlng)を含む別のデータベース(mysql)を維持しています。 mapにマーカーを置く場所が複数ある場合、google devツールにはuncaught Range error: maximum call stack size exceeded
と表示されます。私はインターウェブ内のすべての情報源を試しましたが、すべての結果は否定的です。範囲エラー:Googleマップの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;
}
}
});
});
});
このコードは、あなたのコードは、データ文字列の末尾に「****」の余分を追加されたjqueryのAJAXリクエスト
<?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;
}
}
?>
あなたのデータを複数のポイントのように見えるん何:あなたのPHPは(それが完了したときにのみ出力に文字列をエコー)でなければなりませんように
が見えますか? – geocodezip
投稿されたコードは報告されたエラーを表示しません(少なくとも私が期待しているデータを提供した場合) – geocodezip
エラーはそれをすべて示しています。あなたは、最終的にスタックのオーバーフローを引き起こす多くの関数を呼び出す無限ループを生成するバグ、またはデータが大きすぎて同じことを引き起こすバグがあります。前者の場合は、バグを修正してください。後者の場合は、setTimeoutを呼び出してコードを書き換えて、呼び出しがイベントループによってトリガーされるようにします。 – Will