2013-03-21 91 views
0

我有一個數據庫驅動的網站,它提取的地址和地址顯示在谷歌地圖上。這是包含谷歌地圖嵌入的字符串。我沒有位置的緯度,但我有地址和區域。地點沒有出現。動態谷歌地圖位置PHP和MySQL驅動

<?php $add = $row_rsDoc['Address']; 
$address = str_replace(" ","+",$add); 
$gtown = str_replace(" ","+",$row_rsDoc['Town']); 
$gprov = str_replace(" ","+",$row_rsDoc['Province']); 

$googlestr=$address.','.'+'.$gtown.','.'+'.$gprov; 
echo $googlestr; 
?> 
<th width="446" class="entry" scope="col"><iframe width="441" height="243" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.za/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo $googlestr; ?>&amp;aq=&amp;sll=-26.178375,28.033719&amp;ie=UTF8&amp;hq=&amp;hnear=&amp;radius=15000&amp;t=m&amp;output=embed"></iframe><br /> 

回答

0

而不是使用str_replace()使用urlencode()的(見urlencode()文檔)

此外,你包括你的URL位置COORDS,嘗試使用此:

<th width="446" class="entry" scope="col"><iframe width="441" height="243" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.za/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo $googlestr; ?>&amp;aq=&amp;ie=UTF8&amp;output=embed"></iframe><br /> 
0

您需要對您的地址進行地理編碼以獲取長/緯,然後使用標記和覆蓋圖將標記嵌入到Google地圖中。有一個很好的例子,說明如何在Google地圖文檔上做到這一點,包括如何應用靜態標記以及如何進行地理編碼。

這個過程就像這樣。

在地址添加 - >請求地理編碼 - >存儲返回長/緯度到數據庫 - >在地圖上加載通過ajax回調到一個PHP頁面,返回一個數組的長/拉特在地圖上標記。

它正是我的做法,它最大限度地減少了針對google api所做的實際查詢次數,因爲它對自由用戶的請求有限。如果你想要真正的代碼讓我知道我可以複製和粘貼我的一個應用程序,這正是這個。