我有一张地图,我想做的是将一些表格放入信息窗口。我通过混合 java-script 和 php 来实现这一点(这两个我都不熟悉)。所以我的问题是为什么我的地图没有显示?当我去查看源代码时,一切都是我想要的,但是有些愚蠢导致地图不显示。我已经在下面发布了代码,希望更熟练的眼睛可以发现问题。请放轻松,我只写了大约 6 个月的代码,仍然犯了很多错误。
所以我遇到的问题是这部分
"<?php
$cnt = 0;
foreach ($default_properties as $prop_key => $value) {
?>"
'<div class="view-row">'
'<div class="view-label">'."<?php echo $prop_key?>".'</div>' +;
'<div class="view-value">'. "<?php echo $value?>".'</div>' +;
'</div>'; "<?php
$cnt++;
}
if ($node_id > 0) {
foreach ($node_values as $prop_key => $value) {
?>"
'<div class="view-row">'
'<div class="view-label">'."<?php echo $prop_key?>".'</div>' +;
'<div class="view-value">'. "<?php echo $value?>".'</div>' +;
'</div>';<?php
$cnt++;
}
}
?>"
我可以操纵上述部分,以便加载数组,但我无法格式化它。这样它格式正确但不加载地图。但是当我查看地图的源代码时,一切都在那里!所以我很困惑。
完整脚本如下
<script type="text/javascript">
var infowindow = new google.maps.InfoWindow();
var browserSupportFlag = new Boolean();
function initialize()
{
var latlng = new google.maps.LatLng(38.9550040,-77.4045560);
var settings =
//sets the settings of the map
{
zoom: 5,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("map_canvas"), settings);
// Try W3C Geolocation (Preferred)
if(navigator.geolocation)
{
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position)
{
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
}, function()
{
handleNoGeolocation(browserSupportFlag);
});
}
// Browser doesn't support Geolocation
else
{
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag)
{
if (errorFlag == true)
{
alert("Geolocation service failed.");
initialLocation = Virgina;
}
else
{
alert("Your browser doesn't support geolocation. We've placed you in here.");
initialLocation = '';
}
map.setCenter(initialLocation);
}
}
// Takes an address and places a marker in google maps
function codeAddress()
{
var address = "<?php echo $node_address?>";
var description = "<?php echo $node_title?>";
var property = "<?php echo $default_properties?>";
var values = "<?php echo $node_values?>";
<?php
$js_array = json_encode($end_node_addresses);
echo "var end_addresses = ". $js_array . ";\n";
?>
var image = "<?php echo $entity_icon?>";
geocoder.geocode( { 'address': address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var contentString = '<div id="contentmarker">'+
'<div id="siteNotice">'+
'</div>'+
'<h2 id="firstHeading" class="firstHeading"><?php echo $node_title?></h2>'+
'<div id="bodyContent">'+
'<p> Is a <?php echo $entity_name?> located in<?php echo $node_address?></br> "<?php
$cnt = 0;
foreach ($default_properties as $prop_key => $value) {
?>"
'<div class="view-row">'
'<div class="view-label">'."<?php echo $prop_key?>".'</div>' +;
'<div class="view-value">'. "<?php echo $value?>".'</div>' +;
'</div>'; "<?php
$cnt++;
}
if ($node_id > 0) {
foreach ($node_values as $prop_key => $value) {
?>"
'<div class="view-row">'
'<div class="view-label">'."<?php echo $prop_key?>".'</div>' +;
'<div class="view-value">'. "<?php echo $value?>".'</div>' +;
'</div>';<?php
$cnt++;
}
}
?>" <b></b></p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow(
{
content: contentString
});
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: image,
title: address
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
var title_vars = end_addresses;
for (i = 0; i < end_addresses.length; i++)
{
geocoder.geocode( { 'address': end_addresses[i]}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var contentString = '<div id="contentmarker">'+
'<div id="siteNotice">'+
'</div>'+
'<h2 id="firstHeading" class="firstHeading"><?php echo $node_title?></h2>'+
'<div id="bodyContent">'+
'<p> Is located in "<?php echo $js_array?>"</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: image,
title: title_vars.shift(),
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
</script>