6

I'm making a simple app that will load a google map. but the problem is everytime I load this

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

It wont run on my android emulator while on desktop it works fine. how can I let Phonegap or Android allow external scripts to work/load?

UPDATE: I always get this error "Application Error: The connection to the server was unsuccessful.(file///android_asset/www/index.html). But if I removed the google map script. it works.

psycrow117
  • 63
  • 1
  • 6

3 Answers3

3

Actually, the whitelist is the issue like @TDeBailleul said, but he was referring to the location of the whitelist in iOS not Android.

In android, it is in /res/xml/PhoneGap.xml

There is an example of this file in this answer: https://stackoverflow.com/a/9187479/878602

Community
  • 1
  • 1
Devgeeks
  • 5,659
  • 4
  • 28
  • 35
  • It's still not working. I haven't tried it on an actual phone though. This is my only problem on PhoneGap right now. – psycrow117 Feb 21 '12 at 08:13
  • Maybe some more of what you are trying to do? I certainly get no errors including that script tag in a vanilla app – Devgeeks Feb 22 '12 at 03:07
  • Can you please give me a sample of your phonegap.xml? here is mine but does not work. ` ` – psycrow117 Feb 23 '12 at 01:37
  • Can I know what version of PhoneGap are you using with the vanilla app you made? – psycrow117 Feb 23 '12 at 02:28
  • Well, I would try just putting "http://*" as an access origin to determine if that is the problem. The google maps scripts call lots of other scripts on other domains (http://maps.gstatic.com for instance) so it would be best to just rule it out. Also I am using 1.4.1 – Devgeeks Feb 23 '12 at 06:22
  • 1
    It works! Thanks a lot. looks like there is something wrong with my emulator. I just managed to get an android phone and tested it out. Thanks! – psycrow117 Feb 24 '12 at 03:18
0

In the lastest PhoneGap version(2.7.0). You should modify the file "config.xml" located in /res/ directory of your Android project. Simply add:

<access origin="http://www.yourdomain.com" subdomains="true" />

Domains are assumed blocked unless set otherwise.

0

In the phonegap version 5.1 things are different than the above answers.

There is a plugin installed called cordova-plugin-whitelist. Read the file at plugins/cordova-plugin-whitelist/README.md to know details.

There are multiple kind of whitelist(navigation, intent and access-origin) and in this case you need the content-security -policy.

<!-- Enable all requests, inline styles, and eval() -->
<meta http-equiv="Content-Security-Policy" content="script-src: 'self' 'unsafe-inline' 'unsafe-eval' 'https://maps.google.com'">
cnvzmxcvmcx
  • 1,061
  • 2
  • 15
  • 32