星期三, 7月 16, 2008

Google Maps API within IE & Firefox

最近嘗試使用Google Maps API來練習一些地圖應用。起步較晚唯一的好處,就是網路上的參考資源非常豐富了,這裡整理一些有用的連結參考:
  1. Google Maps API參考文件
  2. Google Maps API教程
  3. 網友自製教程:範例1.  範例2.  範例3.
如果在Javascript, PHP, CSS, DOM等甚至HTML的網路程式上有困難的,還有一個很棒的網頁可以參考:http://www.w3schools.com/

在摸索過程中,基本上還算順利,主要是在一個瀏覽器的問題上卡比較久:用IE和Firefox使用網路上的範例去查詢「台中市三民路」等地址時,會出現不同結果!?(我找到的所有範例都有這問題)


IE結果3筆:
  • 北區三民路三段(24.152721, 120.685339)
  • 西區三民路一段(24.13436, 120.671262)
  • 中區三民路二段(24.142386, 120.679579)
FireFox結果1筆:
  • 豐原三民路郵局(24.253572, 120.720066)
IE的結果是比較正確的,但為什麼有這種差異呢?(Google Maps官方網址則沒有此問題)
找了好久才找到Google論壇裡的這篇文章,內容提到:
I found out that the difference really is in the language settings. It is strange because in both Firefox and IE I supply the same address string. But with different results. After adding the country name (Netherlands) to the address string, it displayed the map in Firefox. Btw right under the map there is a link to the terms of use. Internet Explorer showed the text in Dutch and Firefox in English. I actually missed that.

重點就在於地址前面必須加上國家名稱「台灣省」,Firefox才能正確解析。
另外,若要在地圖下方顯示中文「地圖資料」的話,記得在那段API key的網址裡加上「hl=zh-TW&」即可。

0 意見: