Does Google Maps support KML regions? - kml

Does Google Maps support KML regions like Google Earth does?
Google gives a nice description/tutorial of regions here:
https://developers.google.com/kml/documentation/regions
which mentions Google Earth specifically, but not Google Maps.
According to https://developers.google.com/kml/documentation/kmlelementsinmaps
Google Maps DOES support KML regions, but https://developers.google.com/kml/documentation/mapsSupport doesn't mention them explicitly.
Zoom levels in kml files on google maps
is also ambigious on the issue.
I created my own test KML file (stolen almost verbatim from google):
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Flat Region</name>
<Region>
<LatLonAltBox>
<north>37.430419921875</north>
<south>37.41943359375</south>
<east>-122.080078125</east>
<west>-122.091064453125</west>
</LatLonAltBox>
<Lod>
<minLodPixels>128</minLodPixels>
</Lod>
</Region>
<GroundOverlay>
<name>Mountain View DOQQ</name>
<Icon>
<href>http://data.bcinfo3.barrycarter.info/graphpaper.gif</href>
</Icon>
<LatLonBox>
<north>37.430419921875</north>
<south>37.41943359375</south>
<east>-122.080078125</east>
<west>-122.091064453125</west>
</LatLonBox>
</GroundOverlay>
</Document>
</kml>
You can see it here:
http://test.bcinfo3.barrycarter.info/bc-image-overlay.pl?url=regiontest.kml&center=37.425,-122.085&zoom=15
As you zoom out, the image remains visible (albeit as a
white square) even when it's only a few pixels on each side.
Does the "minLodPixels" setting of 128 in the KML file mean
it should stop being visible once it takes up fewer than 128
pixels?
If so, would this prove Google Maps does NOT support KML regions?
Or am I misunderstanding something?

I can't give you a completed solution but I tried to avoid overcrowding of my points using Regions in maps about a year ago (asked a similar question on SO) and it was my understanding that KmlLayer would not recognize regions and instead just load everything. The only reference I can find to this are forum posts though e.g.: http://code.google.com/p/gmaps-api-issues/issues/detail?id=3142
That said it was my understanding at the time that this could be achieved by using the API to add the overlays and regions in javascript - I just looked and I can not find a good example of this (or any example at all).
It does seem to me though that it should be pretty easy to write a custom Overlay and override the draw function to take account of the size of the overlay before showing / hiding as the map is zoomed: https://developers.google.com/maps/documentation/javascript/overlays#Drawing
Which is the path I intend on taking when we implement some of the features we need around it - but does not solve having this implemented directly from the KML. What is interesting is you link to the documentation indicating it is supported.

Related

Resize or show a 2+ GB KMZ file

I'm using SimpleKML to create a list of ~600 geotagged pictures (where each pin has an image as the description. So I click one of the pins on the map and it shows the picture I took at that coordinate).
The KMZ file is roughly 1GB and doesn't seem to open in Google Earth Pro. I've been looking around online and it seems that it may be too large of a file size to open. However, I have seen that Earth is capable of showing over a million coordinates. If I don't add the images as the description, the file shrinks to ~5kb and is able to work.
How can I open the file keeping the images as the description? Is there indeed an upper limit to file size?
(Note: I'm not sure if it's a Python/programming question, or Google Earth question so for now I am assuming it's a generic Google Earth question).
Google Earth Pro has both 32-bit and 64-bit versions. The 32-bit version limits access to 2GB memory and A 1-2 GB KMZ file is most likely larger than 2 GB when uncompressed which exceeds the memory available to Google Earth.
Google Earth itself can handle many GBs of data but not all at once. The only way to make that much data available to Google Earth is to have the KML file load a subset of the pictures at a time.
If the geotagged pictures are physically separable then you could create multiple KMLs where each KML represents a region and the photos in that region. Each KML file can be referenced by a parent KML file via a NetworkLink. NetworkLink would require a Region element to specify when to load the KML file with the geotagged pictures in a given region. The Region contains a bounding box (<LatLonAltBox>) that describes an area of interest defined by geographic coordinates and altitudes. In addition, a Region contains a LOD (level of detail) extent that defines a validity range of the associated Region in terms of projected screen size in pixels.
Your root KML would be structured like this:
<Document>
<NetworkLink>
<Region>
...
</Region>
<Link>
<href>1.kml</href>
</Link>
</NetworkLink>
...
</Document>
Getting the Regions to work takes trial and error. You can measure the "screen" pixels dimensions for Regions with this KML screen ruler.
Here are two tutorials for working with Regions:
https://developers.google.com/kml/documentation/regions
https://www.google.com/earth/outreach/learn/avoiding-overload-with-regions/
Alternatively, you can create several KMZ files each with a subset of geotagged pictures. You could tie the sub KMZ files together with a parent KML file with radioFolder List style and NetworkLinks with each of the KMZ files. This allows you to select any of the sub-KMZ files with photos but only one at a time to prevent memory overload.
<Document>
<Style id="radioStyle">
<ListStyle>
<listItemType>radioFolder</listItemType>
</ListStyle>
</Style>
<styleUrl>#radioStyle</styleUrl>
<NetworkLink>
<visibility>0</visibility>
<Link>
<href>1.kml</href>
</Link>
</NetworkLink>
<NetworkLink>
<visibility>0</visibility>
<Link>
<href>2.kml</href>
</Link>
</NetworkLink>
</Document>
If you want one of the KML files to be viewable by default when opened in Google Earth then change its visibility to "1" and leave the others as "0".
The SimpleKML API supports networklinks, Regions, KMZ, etc. so it is best to experiment and try different KML output to see what works better.

KML file without coordinates

Is it possible to create a KML file without coordinates in it? I have a list of addresses and I don't have the long/lat. I'd like to create a KML file and have Google Earth geocode and determine the long/lat for each placemark. Thanks in advance.
The geometry (e.g. Point, Polygon, etc.) in a KML Placemark is not required.
You can just have an address in your KML placemarks and Google Earth will automatically geodecode it for you if it can. Under the covers Google Earth will perform a lookup on that address and use the first match if any results are returned. Basically, the resolved address will be the same as if you entered an address via search panel in Google Earth or Google Maps.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>Google place</name>
<address>1600 Amphitheatre Parkway, Mountain View, CA</address>
</Placemark>
</kml>
After that if you save your KML then Google Earth will have inserted the coordinates for you into each Placemark.
<Point>
<coordinates>-122.083954,37.421998,0</coordinates>
</Point>
You can create KML file without coordinates when you have an address in your file. You can input the data from MS Excel for instance, if you are interested a batch operation. See the solution below:
http://www.mkrgeo-blog.com/input-a-multiple-address-list-in-google-maps-and-google-earth-the-quickest-way/
Then Google Earth will geocode your placemarks automatically when save it as a .kml file again.
It only works when you have no additional data in your excel column. If so, then you must import the Excel spreadsheet to the Google Earth directly, as per the explanation below:
https://gis.stackexchange.com/questions/298570/exporting-layer-from-google-my-maps-as-kml-has-no-geometries/332642#332642

Is there any maximum size for KML files to open in Google Earth/

I have created a kml file with 15.439 contour and each one has 360 coordinates. The file size is 369Mb.
When I try to open the file, Google Earth shows a message saying:
"Google Earth encountered a problem and needs to close. We are sorry for the inconvenience."
Is there any size restrictions for KML files? I have verified the kml code and it's ok. It works perfectly with 950 contours and 16Mb.
Is there any other program able to open this kml file?
Thanks for the help!
jluiz20
Your KML file has over 3 million coordinates which is hitting some upper limit for a single KML file in Google Earth. You can scale to that number of contours/features and more if you break it up into smaller KML files, load them in a parent KML via NetworkLinks, and use Regions to only load those features that are in view.
Google Earth can scale up to millions of points and features but not all at once.
If the 15,439 features are geographically separable then you can break up the KML by some geographic grouping or fixed gridded area each in its own KML. Maybe 15 KML files each with 1000 features might be a good starting place.
The parent KML should have each NetworkLink with the appropriate Region and Level of detail (Lod) element to prevent all of the KML files from loading all at once.
Here's the structure of the parent KML file:
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<NetworkLink>
<name>area 1</name>
<Region>
<LatLonAltBox>
<north>xx</north>
<south>xx</south>
<east>xx</east>
<west>xx</west>
</LatLonAltBox>
<Lod>
<minLodPixels>32</minLodPixels>
</Lod>
</Region>
<Link>
<href>1.kml</href>
</Link>
</NetworkLink>
<NetworkLink>
<name>area 2</name>
...
</NetworkLink>
...
</Document>
</kml>
Yes there are restrictions. Check out the docs under
https://developers.google.com/kml/documentation/mapsSupport?csw=1
I ran into similar problems with a 60mb file.
You can use the workaround using Network links but according the docs they only support less than 10.

How to properly update Google Earth KML using NetworkLinkControl and the Java API for KML (JAK)?

I'm building an application that serves up data to a standalone Google Earth client. I want to send over an initial set of data, then update it dynamically using <NetworkLinkControl> and <Update><cookie> tags as things change on the server. I'm generating the KML using the Java API for KML (JAK) library. Unfortunately, while I can confirm that GE is refreshing my NetworkLink and pulling down the Updates I'm sending, none of my updates are showing up in GE. After lots of reading, it seems like it might be that the Update's <targetHref> might be the issue, but I'm 99.9% sure I'm sending over the same string.
Part of what has me confused is that I've seen conflicting info on whether or not the <cookie> element's value needs to be appended to <targetHref>. I did actually see one early prototype updating when I was serving up hand-written test KML files from a static server URL, so I suspect it's not. Actually, that's what's frustrating at the moment: I've seen updating work on my own machine, but can't get it working now with what looks like valid and correct KML.
The current setup looks like this (extraneous XML namespaces stripped for clarity; "$CLIENT_ID" is a GUID-like string):
Root KML file served from http://server/kml/${CLIENT_ID}:
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><NetworkLink>
<Link>
<href>http://server/kmlupdates/${CLIENT_ID}</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1.0</refreshInterval>
<viewRefreshTime>0.0</viewRefreshTime>
<viewBoundScale>0.0</viewBoundScale>
</Link>
</NetworkLink></kml>
Initial content KML served from http://server/kmlupdates/${CLIENT_ID}:
<kml><NetworkLinkControl>
<minRefreshPeriod>0.0</minRefreshPeriod>
<maxSessionLength>-1.0</maxSessionLength>
<cookie>cookie=0|kmlRequestType=updates|projectID=6|lastUpdateSeenIndex=-1</cookie>
</NetworkLinkControl>
<Document id="myProject">
<name>My ProjectProject</name>
<Placemark id="pm1"><name>point1</name>
<Point><coordinates>-117.0,35.0</coordinates></Point>
</Placemark>
</Document></kml>
Later update KML served from http://server/kmlupdates/${CLIENT_ID}:
<kml><NetworkLinkControl>
<minRefreshPeriod>0.0</minRefreshPeriod>
<maxSessionLength>-1.0</maxSessionLength>
<cookie>cookie=0|kmlRequestType=updates|projectID=6|lastUpdateSeenIndex=0</cookie>
<Update>
<targetHref>http://server/kmlupdates/${CLIENT_ID}</targetHref>
<Change>
<Placemark targetId="pm1">
<name>Name changed by Update Change</name>
</Placemark>
</Change>
</Update>
</NetworkLinkControl></kml>
If anyone has any suggestions on what I'm missing here, I'd greatly appreciate it. Thanks!
My original version of the question left out two facts that turned out to be relevant: 1) I'm using the Java API for KML to generate this, and 2) the XML namespaces inside <kml>. I finally figured this out after reading this Google KML Group post for the umpteenth time.
The problem is the last XML namespace, "xmlns:xal". For some reason, removing that from the KML allows the <Update> tags to actually change the items in Google Earth. JAK doesn't let you change the namespaces, but you can strip it manually from the marshaled string.
Absolutely bizarre, but at least I found a solution.
As per https://developers.google.com/kml/documentation/kmlreference:
<xal:AddressDetails> is used by KML for geocoding in Google Maps only.
Currently, Google Earth does not use this element; use <address> instead.
I have some sample using different approach to do something else here maybe related to yours (as your purpose "send over an initial set of data, then update it dynamically using tags") :
https://sites.google.com/site/canadadennischen888/home/kml/auto-refresh-3d-tracking
Approach is that all changes are from server Restful service. Hope it helps. Details as :
How to make a dynamic Auto refresh 3D Tracking :
prepare a RestFul service to generate KML file from DB (KML sample as inside above link)
My other jsp code will generate a KMZ file which has a link to my Restful service. KMZ file has onInterval ( as in the bottom)
Jsp web page allow user to download KMZ file.
When Google Earth open KMZ file, Google Earth will auto refresh to get new data from that Restful service
Everytime refreshing, server will send the latest update KML data with new data to GE.
KMZ sample:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<NetworkLink>
<name>Dennis_Chen_Canada#Hotmail.com</name>
<open>1</open>
<Link>
<href>http://localhost:9080/google-earth-project/rest/kml/10001/20002</href>
<refreshMode>onInterval</refreshMode>
</Link>
</NetworkLink>
</kml>

How to display a moving boat in Google Earth?

I am new to the KML format and try to figure out how to display a boat (a png), moving from a place to another along a path (a simple line drawn composed of several lines).
I can see how to display a Placemark, even with an icon, and a Path, separately.
What I would like to see when I click on the KML file is :
the boat appearing at the departure point;
the path drawing itself until the arrival;
the boat icon moving at a comfortable speed (bonus point it I can set a ration time / progress, extra bonus if I can click on start, pause or rewind) from departure to arrival along the path.
Is that even possible ? I know it is with Google Map, but you can program it with Javascript, which eases things a lot.
This is an old question, and there is now a better way to move a placemark (or even better a model) along a pre-determined linestring. Look into using this feature:
http://code.google.com/apis/kml/documentation/kmlreference.html#gxtrack
Sample code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Folder>
<Placemark>
<gx:Track>
<when>2010-05-28T02:02:09Z</when>
<when>2010-05-28T02:02:35Z</when>
<when>2010-05-28T02:02:44Z</when>
<when>2010-05-28T02:02:53Z</when>
<when>2010-05-28T02:02:54Z</when>
<when>2010-05-28T02:02:55Z</when>
<when>2010-05-28T02:02:56Z</when>
<gx:coord>-122.207881 37.371915 156.000000</gx:coord>
<gx:coord>-122.205712 37.373288 152.000000</gx:coord>
<gx:coord>-122.204678 37.373939 147.000000</gx:coord>
<gx:coord>-122.203572 37.374630 142.199997</gx:coord>
<gx:coord>-122.203451 37.374706 141.800003</gx:coord>
<gx:coord>-122.203329 37.374780 141.199997</gx:coord>
<gx:coord>-122.203207 37.374857 140.199997</gx:coord>
</gx:Track>
</Placemark>
</Folder>
</kml>
The only way I've been able to make this work in static KML is to interpolate between the start and stop points and add placemarks for each frame I want to animate. So, from t=0 to t=1, draw a placemark at the start point. From t=1 to t=2, draw a placemark at the next point, etc.
This gives you the temporal player bar in Google Earth and you can rewind or advance the animation. However it is a little annoying because you wind up with every interpolation point in your placemark tree. Putting the placemarks in their own folder keeps them out of the way, but there's no way to hide them from the user.
Take a look at http://code.google.com/apis/kml/documentation/time.html#animating
The whale shark example does more or less what you want for the placemark. (The URL for the marker icon is broken). Animating the progress along the track can be done using the same trick.
If you want to try something much more difficult, you can try serving dynamic KML. Have Google Earth load a network link to your initial data. Then load another network link with an that sends an update for your placemark at every time tick.
http://code.google.com/apis/kml/documentation/kmlreference.html#link
http://code.google.com/apis/kml/documentation/updates.html
This approach has some serious disadvantages because it requires an external program to drive Google Earth and it does not give the user access to the built-in Google Earth temporal player bar. It also requires that all the data be loaded over a network link -- KML data from a file cannot be updated. That means your driver program needs to act as a http server. Also, in this model it is very hard to know exactly when Google Earth has finished loading and drawing the update. Really I don't recommend doing this; you can make it work using the Google Earth COM API, but it will always be a fragile solution.
There's a browser plug-in that lets you embed Google Earth into a browser page. From there you can use JavaScript to animate your placemark, change your paths, etc. Check out the Google Earth API Developer's Guide.
If you are going to display a boat on Google Earth, a 3D model would be a better approach then an image, since the users can change the viewing angle.
You might want to look into tours: http://code.google.com/apis/kml/documentation/touring.html
I've seen something like this done using a combination of (a number of) <gx:AnimatedUpdate> tags to move a previously created placemark representing your boat and <gx:FlyTo> tags to move the view (I think) all within a <gx:Playlist>.
Hope this helps.
I'm presuming this functionality did not exist when originally answered, but you can achieve the effect using a tour. The following shows a placemark moving in this fashion.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document>
<Placemark id="boat">
<Point>
<coordinates>0,0</coordinates>
</Point>
</Placemark>
<gx:Tour>
<name>Play me!</name>
<gx:Playlist>
<gx:FlyTo>
<gx:duration>5.0</gx:duration>
<LookAt>
<longitude>0</longitude>
<latitude>0</latitude>
<altitude>0</altitude>
<heading>-95</heading>
<tilt>65</tilt>
<range>250000</range>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
</gx:FlyTo>
<gx:AnimatedUpdate>
<gx:duration>5.0</gx:duration>
<Update>
<targetHref/>
<Change>
<Placemark targetId="boat">
<Point>
<coordinates>1,1</coordinates>
</Point>
</Placemark>
</Change>
</Update>
</gx:AnimatedUpdate>
<gx:Wait>
<gx:duration>6.0</gx:duration>
</gx:Wait>
</gx:Playlist>
</gx:Tour>
</Document>
</kml>
The path could be marked with points whose visibility is altered by the tour at the appropriate time.
I have following sample in Google site. Hope this help.
(details inside : https://sites.google.com/site/canadadennischen888/home/kml/auto-refresh-3d-tracking)
prepare a RestFul service to generate KML file from DB
(sample as in https://sites.google.com/site/canadadennischen888/home/kml/3d-tracking)
My other code will generate a KMZ file which has a link to my Restful service
(sample as in this page)
KMZ file has onInterval
Web page allow user to download KMZ file which has URL that link to my Restful service
When Google Earth open KMZ file, Google Earth will auto refresh to get new data from that Restful service
Just google for "kml time animation"
KML: Time and Animation
KML: Animation
Animation and Dynamic Updates with KML

Resources