为什么我的地图没有加载

时间:2012-08-31 21:23:48

标签: php javascript html

我有一张地图,我想要做的是在信息窗口中获取一些表格。我已经完成了通过混合java脚本和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> 

1 个答案:

答案 0 :(得分:0)

让我们继续删除这些引号:

<?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++;
    }

    } 
?>

不破坏PHP:

<?php
    $cnt = 0;
    foreach ($default_properties as $prop_key => $value) {

    echo '<div class="view-row"><div class="view-label">' . 
        $prop_key . '</div><div class="view-value">' . 
        $value . '</div></div>';

      $cnt++;
    }

    if ($node_id > 0) {

    foreach ($node_values as $prop_key => $value) {

    echo '<div class="view-row"><div class="view-label">' . 
        $prop_key . '</div><div class="view-value">' . 
        $value . '</div></div>';

      $cnt++;
    }

    } 
?>