2013-10-15 86 views
11

我一直有一些問題,讓地圖在兩個真正的Android手機上正確顯示 - 一個運行2.2.2和一個運行4.2.2。後者在涉及地圖時總是給我一些悲傷。我已經把它放在另一個線程here中,因爲我已經部分地解決了它。Phonegap Build:Whitelisting谷歌地圖API v3的域名

注:我正在使用Dreamweaver CS6的Phonegap Build。只是一個沒有清單xml文件的config.xml。

現在我有另一個問題,我必須將所有域列入白名單,以便地圖在4.2.2上正常運行,我不知道爲什麼。 最初我在config.xml中有這樣的:

<access origin="*.googleapis.com" /> 
<access origin="*.gstatic.com" /> 
<access origin="*.google.com" /> 
<access origin="maps.googleapis.com" /> 
<access origin="maps.gstatic.com" /> 
<access origin="mt0.googleapis.com" /> 
<access origin="mt1.googleapis.com" /> 
<access origin="csi.gstatic.com" /> 

雖然這工作完全爲Android 2.2.2我會得到4.2.2以下問題:

  • 地圖的底部丟掉了最後瓷磚的行(如果我使用HTTPS在谷歌地圖SRC)
  • 標記在所有

不會顯示由剛剛白名單的一切,所有的這些問題就消失了。然而,我不想將所有內容列入白名單,所以有人知道我是否在這裏丟失了某些東西?

任何幫助非常感謝。

編輯:據我所知,通過使用* .googleapis.com我還將包含其餘類似的白名單域。不過,我發現在我的搜索中有幾次iOS需要顯式列出域。雖然目前這可能不適用,但我確實打算在iOS上使用這個應用程序,所以我把它留在了它裏面(除非有人能告訴我它完全無用而不需要;-)。

////////更新1 ////////

通過在Chrome開發者工具的網絡標籤澆築後,我提取的所有由谷歌地圖訪問的網址。通過明確說明他們每個人,一切工作正常,像這樣:

<access origin="https://mts.googleapis.com" subdomains="true"/> 
    <access origin="https://mts0.googleapis.com" subdomains="true"/> 
    <access origin="https://mts1.googleapis.com" subdomains="true"/> 
    <access origin="https://maps.googleapis.com" subdomains="true"/> 
    <access origin="https://fonts.googleapis.com" subdomains="true"/> 
    <access origin="https://maps.gstatic.com" subdomains="true"/> 
    <access origin="https://csi.gstatic.com" subdomains="true"/> 
    <access origin="https://themes.googleusercontent.com" subdomains="true"/> 

這些可能隨時更改,所以這將是很好的,如果我可以只使用一個通配符*每個域的前面,但這樣做不行。我曾經嘗試都將與以下沒有成功的:

<access origin="*.googleapis.com" subdomains="true"/> 
    <access origin="*.gstatic.com" subdomains="true"/> 
    <access origin="*.googleusercontent.com" subdomains="true"/> 


    <access origin="https://*.googleapis.com" subdomains="true"/> 
    <access origin="https://*.gstatic.com" subdomains="true"/> 
    <access origin="https://*.googleusercontent.com" subdomains="true"/> 

任何人有任何想法,爲什麼我不能使用通配符在這些情況下? 乾杯。

////////更新2/ANSWER ////////

多次實驗後,我已經找到了答案。看起來你必須非常明確地在config.xml中編寫標籤,特別是當涉及到允許子域名時 - 顯然指定子域名不適用於通配符,因此需要兩個標籤塊。我終於使兩個設備使用https正確工作,使用以下內容:

<access origin="*.google.com" /> 
    <access origin="*.googleapis.com" /> 
    <access origin="*.gstatic.com" /> 
    <access origin="*.googleusercontent.com" /> 
    <access origin="google.com" subdomains="true"/> 
    <access origin="googleapis.com" subdomains="true"/> 
    <access origin="gstatic.com" subdomains="true"/> 
    <access origin="googleusercontent.com" subdomains="true"/> 

希望這會對某人有用。我仍然不明白爲什麼它能在舊版Android上正常工作。也許有人可以幫助啓發我,如果他們如此感覺?

回答

1

域名白名單的語法已隨PhoneGap版本更改。如果您使用的是3.1或更高版本,請參閱此文檔的語法:http://docs.phonegap.com/en/3.1.0/guide_appdev_whitelist_index.md.html。我想這可能是你的通配符不適合你的原因。

我使用以下和它的作品展示我的谷歌地圖在我的PhoneGap應用程序:

<access origin="*://*.googleapis.com/*" subdomains="true" /> 
<access origin="*://*.gstatic.com/*" subdomains="true" /> 
<access origin="*://*.google.com/*" subdomains="true" /> 
<access origin="*://*.googleusercontent.com/*" subdomains="true" />