0

I'm having a problem running the standard GOOGLE json file load example from my Ubuntu Apache local host. I saw a similar question with an answer that pertained to IIS (How to open a local file with Javascript FileReader()); however, I'm looking for a solution for Apache on Ubuntu.

The json file loads correctly from the remote URL (see code below) but fails to load from my local URL even though I can view it through my browser. I've tried absolute and relative paths.

Data Layer: Simple html, body { height: 100%; margin: 0; padding: 0; } #map { height: 100%; }

 function initMap() {
   map = new google.maps.Map(document.getElementById('map'), {
     zoom: 4,
     center: {lat: -28, lng: 137}
   });
  // This doesn't work even though it works in my FireFox browser
  map.data.loadGeoJson('localhost/google.json'); 
  //This one works
  //map.data.loadGeoJson('https://storage.googleapis.com/mapsdevsite/json/google.json');
 }

Thank you.

Community
  • 1
  • 1
  • Also, are there any js console errors indicating any security policies being violated? – Robert Durgin Sep 18 '16 at 13:08
  • I am new to javascript and linux - so just now installed Firebug. When I run with http://myserver.local I am getting this error: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://myserver.local/google.json. (Reason: CORS header 'Access-Control-Allow-Origin' missing)." When I run with local/google.json I get this error: "NS_ERROR_DOM_BAD_URI: Access to restricted URI denied" – Jane Cleland-Huang Sep 18 '16 at 15:05
  • Correction: When I run with localhost/google.json I get the error: "NS_ERROR_DOM_BAD_URI: Access to restricted URI denied" – Jane Cleland-Huang Sep 18 '16 at 15:13

2 Answers2

0

Have you tried the following?

Add the following to /etc/hosts:

127.0.0.1        myserver       myserver.local

And use: http://myserver.local instead of http://localhost

This makes your browser think it's connecting to a remote server.

Robert Durgin
  • 1,810
  • 19
  • 23
  • Thanks for the suggestion. I have tried this but it still doesn't work. Now I can view the file also from http://myserver.local/google.json but it still won't run from the .html file. – Jane Cleland-Huang Sep 18 '16 at 14:32
0

I haven't exactly solved this the way I wanted to - but I have been able to get everything working now by placing TestGeoJSON.html file (shown above) into var/www/html and then by loading the Json file directly using:

map.data.loadGeoJson('file:///var/www/html/google.json');