2013-10-16 32 views
0

我已經開始使用HTML5和PHP了,但是我有一個關於在我的php文件中插入google map的問題。我要把我寫的樣本代碼。也許任何人都有我的情況的解決方案。我的GoogleMap無法在PHP中工作

在我的第一個文件是'index.html'我有一個輸入和一個按鈕,將提交併發送輸入到php文件。我爲此編寫的代碼如下所示。

<form action="deneme.php" method="post"> 
       <input type="text" name="searchtxt" id="searchtxt" placeholder="Write something to search"></br> 
       <div align="center"> 
       <input type="submit" name="locationbtn" data-icon= "search" data-iconpos="right" data-theme="a" data-inline="true" value="Find Location"></button> 
       </div> 
      </form> 

在我的'deneme.php'文件中,代碼就像那樣。

<!DOCTYPE html> 
<head> 
<meta charset=utf-8> 



<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" /> 
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> 
<link rel="stylesheet" href="css/bgcolor.css" /> 
<meta name="viewport" content="initial-scale=1, maximum-scale=1"> 
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> 
<script type="text/javascript"> 
function TestGeo() 
{ 
    if (navigator.geolocation) 
     { 
      navigator.geolocation.getCurrentPosition(TestMap, error, {maximumAge: 30000, timeout: 10000, enableHighAccuracy: true}); 
    } 
    else 
    { 
      alert("Sorry, but it looks like your browser does not support geolocation."); 
    } 
} 

var map; 
function TestMap(position) 
{ 
     // Define the coordinates as a Google Maps LatLng Object 
     var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 

     // Prepare the map options 
     var mapOptions = 
     { 
        zoom: 10, 
        center: coords, 
        mapTypeControl: false, 
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}, 
        mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     // Create the map, and place it in the map_canvas div 
     map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 

     // Place the initial marker 
     var marker = new google.maps.Marker({ 
        position: coords, 
        map: map, 
        title: "Your current location!" 
     }); 

function error() { 
     alert("Cannot locate user"); 
     } 
</script> 
</head> 


    <body onload="TestGeo();"> 
<?php 
    $t=date("H"); 
    $search=$_REQUEST['searchtxt']; 

     if($t<"18"){ 
     echo ("<br/>Have a good day " . $search . " !"); 
    } 
     else{ 
     echo ("<br/>Have a good night " . $search . " !") ;  
    flush(); 
    flush(); 
     } 

     ?> 
</div> 
      <div id="map_canvas" style="width: 100%; height: 85%; border-right: 1px solid #666666; border-bottom: 1px solid #666666; border-top: 1px solid #666666; border-left: 1px solid #AAAAAA;" align="center"> 
    </div> 

主要的問題是我的deneme.php文件沒有加載谷歌地圖當我點擊提交按鈕,但我有deneme.php文件印刷index.html中輸入的輸入值。我試圖通過從<input>更改爲<button href="#deneme.php" type="button" name="locationbtn" data-icon= "search" onclick="location.href='deneme.php'" data-iconpos="right" data-theme="a" data-inline="true">Find Location</button>後,這樣做,我無法得到在PHP文件中打印的HTML文件輸入的問題來解決問題。但谷歌地圖在這種情況下工作。

回答

1

.html文件通常不是通過PHP解釋器進行處理,而是以純文本形式發送出去。如果您點擊提交按鈕,並在location.html頁面上執行「查看源代碼」,則可能會在其中嵌入原始PHP代碼。嘗試將其重命名爲location.php,將表單更改爲指向此新文件名,然後重試。

+0

對不起,我把它從我的舊模板,當我使它deneme.php它不工作,我現在編輯它,對不起 – Nothingbutageek