2012-08-31 42 views
0

我有一張地圖,我正在嘗試做的是在信息窗口中獲取一些表格。我已經通過混合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> 
+2

什麼都是圍繞單引號和雙引號你的代碼? – Kermit

+0

我被告知我需要他們。某處我認爲這是我無法找到的問題。 – user1639669

回答

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

    } 
?> 
+0

即使當我刪除引號時,就像在沒有脫離PHP的部分中一樣,我仍然會看到白色屏幕。但我可以做到這一點,並獲得地圖填充,但格式是正確的。 <?php \t $ cnt = 0; \t的foreach($ default_properties爲$ prop_key => $值){ \t回聲$ prop_key \t回波$值 \t $ CNT ++; \t} \t \t 如果($ NODE_ID> 0){ \t \t 的foreach($ node_values爲$ prop_key => $值){ \t回聲$ prop_key \t回波$值 \t $ CNT ++; \t} \t \t} \t \t> – user1639669

+0

@ user1639669添加'的error_reporting(E_ALL);?'和'的ini_set( 'display_errors設置', '1');'你的腳本,看看它說。 – Kermit

+0

我打開了錯誤報告,當我遇到錯誤時,它通常會告訴我最新的錯誤信息,爲什麼頁面沒有加載。在這種情況下,這是說。它只是不加載頁面和源代碼告訴我,代碼片在那裏,工作正常。我迷失在這裏,不知道還有什麼要做或者有另一種方式去做。 – user1639669

相關問題