2013-12-13 68 views
1

我想創建一個簡單的PHP代碼,當用戶點擊一個體育場的鏈接時,它會顯示使用谷歌地圖的體育場的位置。但是,當我嘗試點擊體育場時,它沒有顯示確切的位置。我已經多次檢查過代碼,我不知道問題出在哪裏。谷歌地圖不顯示正確的位置

這是地圖的代碼

<html> 
<?php 

session_start(); 
include('dbconn.php'); 

$id=$_GET['id']; 

$sql=mysql_query("SELECT stadium, city, state FROM fixtures where fixtures_id='" .$id ."'"); 

$row= mysql_fetch_array($sql); 

    $stadium = urlencode($row['stadium']); 
    $city = urlencode($row['city']); 
    $state = urlencode($row['state']); 
    $place = "$city,+$stadium,+$state"; 
?> 


<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" 
marginwidth="0" src="https://maps.google.com/maps?  
f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo $place; ?> 
&amp;aq=0&amp;ie=UTF8&amp;hq=&amp;hnear=<?php echo $place; ?> 
&amp;t=m&amp;iwloc=&amp;output=embed"></iframe> 

</html> 

這是我如何存儲體育館,城市和國家我的數據庫裏面enter image description here

這是這是不正確的輸出

enter image description here

回答

3

將經度和緯度信息存儲在數據庫中會更容易,這樣您就可以確保顯示正確的體育場。

有時,如果添加國家名稱和地點而不是地點,地理編碼的效果會更好。根據用戶的位置,只有使用的地方可以去可怕的錯誤...

+0

謝謝!它現在有效 –

1

嘗試存儲lat和長

這裏儘量使有效地址字符串

$place = "$stadium,+$city,+$state";