我目前正在开发一个融合 Yelp 和 Google Maps API 的网络应用程序。我完成了代码,它似乎正在工作,直到我发现谷歌地图不会显示某些搜索词。例如,当我在丹佛搜索披萨时,我的应用程序运行良好,但当我在纽约搜索寿司时,谷歌地图却无法加载。搜索后我检查了我的源代码,结果都在那里。我似乎无法弄清楚是什么问题。该应用程序在线 。
谷歌地图代码片段:
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
//Er word een kaart neergezet
function initialize(lat,lon,label) {
var lancenter =
"<?
echo $latitude_center
?>";
var loncenter =
"<?
echo $longitude_center
?>";
var map;
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(lancenter, loncenter),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var companyLogo = new google.maps.MarkerImage('image.png',
new google.maps.Size(35,60),
new google.maps.Point(0,0),
new google.maps.Point(18,60)
);
var companyShadow = new google.maps.MarkerImage('shadow.png',
new google.maps.Size(69,60),
new google.maps.Point(0,0),
new google.maps.Point(18,60)
);
<?
//Er word een loop gemaakt die de array met resultaten doorloopt en vervolgens markers, infowindows en beschrijving op de kaart plaatst voor alle resultaten.
while($i<sizeof($response["businesses"])) {
$latitude_result = $response["businesses"][$i]["location"]["coordinate"]["latitude"];
$longitude_result = $response["businesses"][$i]["location"]["coordinate"]["longitude"];
$result_description = $response["businesses"][$i]["name"];
$result_rating = $response["businesses"][$i]["rating_img_url_small"];
$result_ratingnr = $response["businesses"][$i]["review_count"];
$result_beschrijving = $response["businesses"][$i]["snippet_text"];
$result_beschrijving=str_replace("\n"," ",$result_beschrijving);
$result_beschrijving=str_replace("\r"," ",$result_beschrijving);
$result_adres0 = $response["businesses"][$i]["location"]["display_address"][$i];
$result_adres1 = $response["businesses"][$i]["location"]["display_address"]["1"];
$result_adres2 = $response["businesses"][$i]["location"]["display_address"]["2"];
$result_adres3 = $response["businesses"][$i]["location"]["display_address"]["3"];
$result_image = $response["businesses"][$i]["image_url"];
$result_url = $response["businesses"][$i]["url"];
$result_image = $result_image ? $result_image : 'noimg.gif';
$result_beschrijving = $result_beschrijving ? $result_beschrijving : 'Er is helaas geen beschrijving beschikbaar voor deze locatie.';
?>
var lanresult =
"<?
echo $latitude_result
?>";
var lonresult =
"<?
echo $longitude_result
?>";
var resultloc = new google.maps.LatLng(lanresult, lonresult);
var beschrijving =
'<h3>'+"<?
echo "<div id='container'>",Naam,":"," ","<h2>", $result_description,"</h2>","</br>",Beschrijving,":"," ","<h2>", $result_beschrijving,"<a href='", $result_url,"' target='_new'>","Lees verder","</a>","</h2>","</br>", Adres,":"," ","<h2>", $result_adres0,"</br>", $result_adres1,"</h2>","</br>", Waardering,":"," ","<img src='", $result_rating,"'/>","<h2>",$result_ratingnr," ",recensies,"</h2>","</br>","<img src='", $result_image,"'/>","</br>","</br>","<h2>","<a href='", $result_url,"' target='_new'>","Lees meer informatie via YELP","</a>","</h2>","</div>"
?>";'</h3>'
var marker<? echo $i; ?> = new google.maps.Marker({
map: map,
icon: companyLogo,
shadow: companyShadow,
position: resultloc,
});
var infowindow<? echo $i; ?>= new google.maps.InfoWindow({
content: beschrijving,
maxWidth: 260
});
google.maps.event.addListener(marker<? echo $i; ?>, 'click', function() {
infowindow<? echo $i; ?>.open(map,marker<? echo $i; ?>);
});
<?
$i++;
} // einde while php
?>
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我真的希望有人能帮助我。
亲切的问候