Reputation: 23
I'm developing a map on my site using google maps JS API. my map has a local JSON layer that defines a certain polygon area on the map. everything went fine when i ran it within the visual-studio, but when i double clicking map.html outside the VisualStudio project the polygon is not shown. why is it?
this is the call for loading the Json layer:
map.data.loadGeoJson(href = "MapLayer.json");
map.data.setStyle({
fillColor: 'red'
});
Upvotes: 1
Views: 10522
Reputation: 2079
Keep it simple, here is the code I am using
data = map.data.loadGeoJson('my.geojson');
map.data.addGeoJson(data);
Just call your geojson file, in this example my.geojson and then add the data to the map.
Upvotes: 0
Reputation: 51
Just put the path to the file in like this.. If you add the console.log(map.data.loadGeoJson) you should be able to see the Google array or it will at least show you the fault by display the console.
map.data.loadGeoJson('PATH TO FILE\MapLayer.json);
console.log(map.data.loadGeoJson)
map.data.setStyle({
fillColor: 'red'
});
Upvotes: 0
Reputation: 117
Have you tried putting this folder inside xampp/wamp/tomcat or another http-server. I suspect google maps is not allowing file:// protocol.
Upvotes: 1
Reputation: 107
The documentation just includes the link and no href. Try removing that. https://developers.google.com/maps/documentation/javascript/datalayer
Upvotes: 0