Loading Google Maps from a kml file on server - kml

My website (www.boatingtrax.com) presents maps from google earth and google maps. I prepare the kml files and load the file to my server. I put links to the various kml files on my site (https://www.boatingtrax.com/notices-to-mariners/news-south-wales-notices-mariners/) and google earth formats are generated. NICE!
I update the kml files daily and a new google earth map is generated.
Google Maps is different. I can produce a google map using the kml file and embed the map on site or share the link Both work well. Also nice!
But I have to do that every time I change the kml files (which is daily). Painful!
Could anyone point me to a process so that I can keep Google Maps updated automatically?
Any help appreciated.

If I understand correctly, your issue is that every time you upload a new KML, it has a new filename, and therefore you need to change your Maps API code to point at the new file each time?
If so, you should probably check out KML Network Links. A KML NetworkLink is a small KML file that contains a pointer to another KML file.
In your case, what I would do is create one NetworkLink KML with a static filename, which always points at your latest data KML. Have your Maps API code load the NetworkLink file, and it will show the target KML. Each time you add a new data KML, you just have to upload a new copy of the NetworkLink KML (with the same filename), which points at the new data KML.
For details on KML Network Links, see these resources:
KML Tutorial - Network Links
KML Reference - NetworkLink
A few things to note... Maps API has some caching of KML files built in, so there may be a delay (minutes?) from when you update the NetworkLink file to when you see the new data on your map. Google Earth supports long strings of nested NetworkLinks, but Maps will only follow a limited number of NetworkLinks (10, I think?), so be careful if you go down the road of nesting them. Also, Google Maps API does not support all the KML elements which Earth does... details here.

Related

Cannot view/access attribute data from KML file in QGIS

Using QGIS, when I convert a SHP file with several columns of attribute data into a KML for use in a Google Environment (e.g. Google Earth, Fusion Tables, Google Maps), I'm not able to view the attribute data following the conversion (while still using QGIS) — all I can see are two columns headers "Name" and "Description" with no cell values. Yet, if I take that same KML and load it into Google Fusion Tables, for example, suddenly all the attributes from the original SHP files are visible.
Is there a way to view the attributes of a KML while in QGIS?
I have not enough reputation to put this in a comment, thats why I give you the hit here...
Think, same problem is discussed here:Not Importing ExtendedData from KML and solution comes with gdal-2.0.2-4

Do KML files have to be on the same domain as the openlayers map?

I'm fairly new to openlayers and I'm trying to simply get a kml to show up on an openlayers map. I have the map and basemap rendering properly in a jsfiddle, after copying out the HTML and javascript from this example here.
I am trying to load a kml that I have hosted on my own domain. The link to it is here. It is just a subset of some water wells data in Alberta, Canada. The code I am using to access the data is:
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'http://www.cdnpolimap.com/alberta_wells.kml',
format: new ol.format.KML()
})
});
However when I look at other people's maps (mostly in other stackoverflow question), I notice that they are all accessing it without all the http://www......" stuff before it. Am I correct in assuming that the javascript file must be saved on the same domain as the kml and then access it using a relative path? And so therefore I can't access the data when writing in a jsfiddle?
I hosted everything on a single domain and I can now confirm that yes, the kml resource has to exist on the same domain as the js script.

Local images are not appearing in kmz

I have information bubble in kml, which shows image along with some data.
That image is a local image which comes from respective folders. I have added a "file" addition before image src path , now i am able to see images on placemark in kml file.
But when I convert this kml file to kmz those images on bubbles are not appearing.
Can any one help me regarding this??
Cheers
Praveen.
Here is an example KMZ file with an image in the infowindow, which works using KmlLayer in the Google Maps API v3 (can't seem to embed the link, so it is below):
KmlLayer
geoxml3
and using Google Maps (no longer supported)
The image is embedded in the KMZ.
The KMZ documentation states:
They can refer to files within the same KMZ file, or to files contained in other KMZ files or stored elsewhere on the web.
Your File:/// reference is not "on the web".
It also states:
However, if you use absolute references to local files, the links will break when the files are moved to a new system. Relative references avoid this problem.

KML visualize data file

I am trying to visualize a large amount of weather data with GE(the data may change time to time). Ideally, the user could input the data file with locations and weather data. I was wondering how could I create the KML dynamically?
Based on your comment above you will have KML data available from one of two sources: See my answer to this question: Import KML in Maps API V2 (I would ignore the solution by the author here):
If you have the KML accessable at a publically available URL, follow this part of the API: https://developers.google.com/kml/documentation/mapsSupport.
If you want to load locally stored KML files (i.e. you are getting a .txt file on your server) you will need to parse them yourself. There are libraries for doing this in every language. For Javascript as an example: http://code.google.com/p/geoxml3/
If you do end up doing this with the API (your kml/kmz is available as a URL) your JavaScript code is as simple as:
The API Call to load KML from a URL in the JavaScript API where the map var is your google.maps.Map object.
var geoLayer = new google.maps.KmlLayer('URL');
geoLayer.setMap(map);
UPDATE
Note that this thread is relevant to your question as well, and you do have additional options to loading your KML if using the GE Plugin. Unable to load a local KMZ file into a browser with the google earth plugin using fetchkml function

Protect KML file from downloading or accessing

I am trying to protect my KML file, from being downloaded or its data extracted easily. All I want is the file to be viewed in google maps or google earth, but no one is allowed to download it or extract the data "easily" (the kml file isnt going to be available publicly). My kml files are a result of deep and exclusive analysis that is a signature I want to hide from competitors.
Also are there any alternatives to convert kml to a format that data cant be obtained easily from it. My KML files have polygons in 3D.
I understand the concept of everything that can be seen can be downloaded or extracted somehow,
I have 4 answers or 0 answers, depending on your project.
Using Google Maps Api for Business (~ 10.000$ per year) you can
generate a Client ID and use that to protect a Fusion Table (can
create in Google Drive) where you can import your KML and which you
then can display using the Google Maps Api. It would be the perfect solution, but without Google Maps Api for Business your Fusion Table is not protected and so anybody can access
it in Google Drive and view and copy-paste the Kml
representation of the polygons.
Using Google Maps Engine (/Lite) you can import your
Kml to Google as well (if you use Lite then you first need to import to Google
"My Maps" and from within Google Maps Engine Lite you can then
import from "My Maps"). I don't know the pricing for non-lite. A
Google Maps Engine Map can be shared so its only viewable and in
this only viewable version I have not found a way to download or
view the raw-kml-data which would be what we want. Sounds all good,
but you are limited to 3 layers in Maps Engine Lite and I have not found a way to import all my polygons (districts in
my case) into one layer at once. I can only import them bit by bit as it seems (managed to import 10 polygons with a total of 353 Points into one layer). Each import results in one layer, can't move stuff from one layer to another and for some reason there are some polygons that I can't seem to import. Edit:
I can import all polygons, one polygon (due to algorithmic simplification of my polygons) got an intersection (line crossing) and as soon as I fixed that part the import didn't throw any errors anymore, but I see now that I can only embed that map using an iframe having the legend included as well, so this solution is nothing for me.
Restrict access to a KML on your server to Google servers only using a white list of Google Maps servers which might request your
KML. Problem: can't find such a list online... must collect in some
way first.
Also there are blog entries Protecting KML Files from general public access in Google
Maps
and Protect KML / KMZ Files from Unauthorized Access Using
Cryptography
Your question is based on a fallacy of computer security known as "security through obscurity". The fallacy is this. You say you don't want it downloaded "easily." You can make it hard, but as long as its possible as soon as one person figures it out they write a script to do it automatically and its then "easy." There is no answer to your question because it is impossible. Any content you make available is pirateable, and any data is reconstructable.
Why not just save the kml file(s) and cut/paste onto a password encrypted usb drive, like Kingston or Kanguru defender. Then just open the kml from your usb disk.
you can check the $_SERVER["HTTP_USER_AGENT"] variable and if is from google then 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 ...

Resources