I have a large amount of data (thousands of polygons) that I want to share with people through my site. I want them to be able to view the polygons, and due to the large amount of data, I am not worried about them stealing this data through the displayed google map. However, since the kml file must be accessible to google, a proficient coder could discover the url of the kml files and simply download the entire file. Is there any way to restrict access to these kml files only to google so no outside people can get to them. I have tried .htaccess, but I can't figure out how to restrict access to everyone but google. Any ideas?


You could provide as a WMS layer in which case the end users will only have a picture of your data. And with 1000s of polygons it will be faster to download too.

Otherwise I don't think there is any way to display the KML on Google with out allowing general access to your data.

| improve this answer | |
  • I like the idea, but I also want them to be able to click the polygons and get specific info about each individual polygon. A WMS layer would not be able to do that. – user2110 Mar 4 '11 at 14:35
  • WMS has a GetFeatureInfo request that can do exactly that – Ian Turton Mar 4 '11 at 15:05

not a great solution but you could monitor the IP addresses used by Google calling back to your KML and then setup a frontend proxy to only allow those addresses access. Obviously, this list would need to be dynamic and constantly tended to but over time, you might find the block of IPs Google uses for KML Layer callbacks is fairly stable. It would also be great list to post back to this group :)

YMMV, cheers brian

| improve this answer | |

allow access to 66.249.82.* and deny rest others for your kml file using any front end proxy servers or apache/nginx anything you use to serve kml files.

| improve this answer | |

i check the $_SERVER["HTTP_USER_AGENT"] variable for google.

and if is correct i generate the kml from php.

$agent = "Kml-Google";
$google = strpos($_SERVER["HTTP_USER_AGENT"], $agent);
($google !== FALSE) or die;
header('Content-Type: application/vnd.google-earth.kml+xml kml');
header('Content-Disposition: attachment; filename="otras.kml"');
<?xml version="1.0" encoding="UTF-8"?>
<kml xml ...
| improve this answer | |

KML can be partially protected served from a httpaccess passworded directory could be parsed using a third party KML parser.(such as EGeoXml or GeoXml)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy