I am trying to create a route based off lon & lat's. This is what i have so far, but it doesn't seem to be working correctly.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<PlaceMark>
<name>test</name>
<description>test Desc</description>
<Point>
<coordinates>-80.54400115,43.4250264</coordinates>
<coordinates>-80.52674314,43.43127701</coordinates>
...
</Point>
</PlaceMark>
</Document>
<kml>
Is the syntax correct? When i load it up in my maps app, it doesn't show the route.
Please see the KML reference
KML is XML which is case sensitive (PlaceMark is not the same as Placemark)
a <Point> is a single location
a line is a <LineString>
Your XML needs to be valid (</kml> is needed to close the opening <kml>).
example
KML from example above on Google Maps
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2"> <Document>
<Placemark><name>test</name>
<description>test Desc</description>
<LineString>
<coordinates>
-80.54400115,43.4250264
-80.52674314,43.43127701
-80.5274517,43.43458707
-80.53223781,43.43876923
-80.54385782,43.44993036
-80.53949137,43.45723788
-80.53950793,43.46780893
-80.53352615,43.4730443
-80.53491389,43.47816267
-80.54136061,43.48417145
-80.54163034,43.48439869
</coordinates>
</LineString>
</Placemark></Document>
</kml>
Related
I am plotting a LineString. For some reason, I don't seem to effect the LineStyle. My code looks identical to many examples but no matter what color or width I place in the LineStyle, it always comes out as a thick blue line.
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Qtr Min Grid Maker</name>
<LookAt>
<longitude>-121.5</longitude>
<latitude>38</latitude>
<altitude>0</altitude>
<range>740933.8825924395</range>
<tilt>0</tilt>
<heading>0</heading>
</LookAt>
<Folder>
<name>Grids</name>
<Style id="linestyle1">
<LineStyle>
<color>7f0000ff</color>
<width>1</width>
<gx:labelVisibility>1</gx:labelVisibility>
</LineStyle>
</Style>
<Placemark>
<name>QTR</name>
<visibility>0</visibility>
<open>1</open>
<styleUrl>#linestyle1</styleUrl>
<LineString>
<coordinates>
-124.75,40,0
-124.5,40,0
-124.25,40,0
-124,40,0
-123.75,40,0
-123.5,40,0
-123.25,40,0
-123,40,0
</coordinates>
</LineString>
</Placemark>
</Folder>
</Document>
</kml>
It works for me if I move the shared styles to the top level (inside the <Document> tag):
example
From the documentation (see the description of <StyleSelector>):
A style defined within a Feature is called an "inline style" and
applies only to the Feature that contains it. A style defined as the
child of a <Document> is called a "shared style." A shared style must
have an id defined for it. This id is referenced by one or more
Features within the <Document>.
Yours is neither a child of <Document> nor within a <Placemark>
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="linestyle1">
<LineStyle>
<color>7f0000ff</color>
<width>1</width>
<gx:labelVisibility>1</gx:labelVisibility>
</LineStyle>
</Style>
<name>Qtr Min Grid Maker</name>
<LookAt>
<longitude>-121.5</longitude>
<latitude>38</latitude>
<altitude>0</altitude>
<range>740933.8825924395</range>
<tilt>0</tilt>
<heading>0</heading>
</LookAt>
<Folder>
<name>Grids</name>
<Placemark>
<name>QTR</name>
<visibility>0</visibility>
<open>1</open>
<styleUrl>#linestyle1</styleUrl>
<LineString>
<coordinates>
-124.75,40,0
-124.5,40,0
-124.25,40,0
-124,40,0
-123.75,40,0
-123.5,40,0
-123.25,40,0
-123,40,0
</coordinates>
</LineString>
</Placemark>
</Folder>
</Document>
</kml>
I am using Google Earth 5.0 Client. I would like to update a KML file (loaded by a NetworkLink) by clicking on a hyperlink in the description/balloonStyle tag of one of its placemarks.
Here is an example:
A.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml>
<NetworkLink>
<Link>
<href>http://www.example.com/B.kml</href>
</Link>
</NetworkLink>
</kml>
B.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml>
<Document>
<Folder id="entities">
<Folder id="en1_folder">
<Placemark id = "en1_point">
<description>
<a href="http://www.example.com/getConnections.php?en=id1"
type="application/vnd.google-earth.kml+xml"> Get connections </a>
</description>
<Point>
<coordinates>...</coordinates>
</Point>
</Placemark>
</Folder>
There are about 500 such folders, each with its corresponding en# point
containing a description hyperlink.
</Folder>
</Document>
</kml>
If a user clicks on a hyperlink, I want to generate a set of LineStrings connecting that point to one or more other points.
For example, getConnections.php?en=id1 could generate a response like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml>
<Update targetHref="http://www.example.com/B.kml">
<Change>
<Folder targetId="en1_folder">
<Placemark id="en1_connections">
<LineString>
<Coordinates>
(en1_coords), (en5_coords), (en7_coords)
</Coordinates>
</LineString>
</Placemark>
</Folder>
</Change>
</Update>
</kml>
This doesn't work in GE 5.0. I understand that Update is a child of NetworkLinkControl which in turn must be requested by a NetworkLink from the same domain as the KML that contains it.
I know there are several workarounds using one or more NetworkLinks, however I am curious to know if there still exists a way to directly update the same KML file by clicking on the description hyperlink.
Any thoughts appreciated.
Thanks,
Max
I am trying to update a kml file through the networkcontrollink with an update
The kml file i want to update is stored on the server is called initial_coord.kml.
<?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="pm123">
<name>point123</name>
<Point>
<coordinates>-95.44,40.42,0</coordinates>
</Point>
</Placemark>
<Placemark id="pm456">
<name>point456</name>
<Point>
<coordinates>-95.43,40.42,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
The kml file i load to update it is the following:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink>
<name>Update</name>
<Link>
<href>http://localhost/cgi-bin/testF/add_more_coords.py</href></Link>
</NetworkLink>
</kml>
And the python script i am calling is the following
#!/usr/bin/python
kml= (
'<?xml version="1.0" encoding="UTF-8"?>\n'
'<kml xmlns="http://www.opengis.net/kml/2.2">\n'
'<NetworkLinkControl>\n'
'<Update>\n'
'<targetHref>http://10.10.210.247/initial_coords.kml</targetHref>\n'
'<Change>\n'
'<Placemark targetId="pm123">\n'
'<name>Name changed by Update Change</name>\n'
'<!-- coordinates remain the same -->\n'
'</Placemark>\n'
'</Change>\n'
'</Update>\n'
'</NetworkLinkControl>\n'
'</kml>\n'
)
print 'Content-Type: application/vnd.google-earth.kml+xml\n'
print kml
The update does not work and i am wondering why because it is very similar to the google example
The NetworkLinkControl is strict regarding the target URL and you have localhost in the root KML and 10.10.210.247 in the python-generated output. Most match exactly to work correctly.
<Link>
<href>http://localhost/cgi-bin/testF/add_more_coords.py</href></Link>
</NetworkLink>
<Update>
'<targetHref>http://10.10.210.247/initial_coords.kml</targetHref>\n'
<Update>
You'll notice the targetUrl and NetworkLink URL matching in the tutorial.
Try putting the IP address in the root KML file to match what is generated in the python.
<NetworkLink>
<Link>
<href>http://10.10.210.247/cgi-bin/testF/add_more_coords.py</href>
</Link>
</NetworkLink>
<Update>
'<targetHref>http://10.10.210.247/cgi-bin/testF/add_more_coords.py</targetHref>\n'
<Update>
I made a KML file to mimic an example from "
High Performance KML for Maps and Earth'-on YouTube-link (at 15:11-16:05 or just 15:51)
I get the error:
Validation stopped at line 2, column 45: no declaration found for element 'kml'
When I try to run this code GOOGLE EARTH crashes.
Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<gx:Track>
<when>13:51</when>
<gx:coord>-147.871 64.861</gx:coord>
<ExtendedData>
<SchemaData schemaUrl="#schema">
<gx:SimpleArrayData name="PM 2.5">
<gx:value>0.0</gx:value>
<gx:value>-6.0511e+15</gx:value>
<gx:value>180</gx:value>
</gx:SimpleArrayData>
</SchemaData>
</ExtendedData>
</gx:Track>
</Placemark>
<Placemark>
<gx:Track>
<when>13:56</when>
<gx:coord>-147.871 64.861</gx:coord>
<ExtendedData>
<SchemaData schemaUrl="#schema">
<gx:SimpleArrayData name="PM 2.5">
<gx:value>0.0</gx:value>
<gx:value>-1.0001e+16</gx:value>
<gx:value>180</gx:value>
</gx:SimpleArrayData>
</SchemaData>
</ExtendedData>
</gx:Track>
</Placemark>
</kml>
This is a shorter version of my actual full kml file
You are not using a correct format for the KML file
Firstly, while this is correct for most cases
<kml xmlns="http://www.opengis.net/kml/2.2">
I prefer to use this (I forget why but I do)
<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">
but your main problem is you are also missing a <Document>
so the actual file should look like this
<?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">
<Document>
<name>Name</name>
<Placemark>
...
</Placemark>
</Document>
</kml>
How do you links cities with a curve (line) in kml for Google Earth?
First, since you are on SO I'm assuming you are asking from a KML perspective and not just in the desktop application.
You would need to have the coordinates of the two cities. Then you would create a kml document like the following from the docs using your coordinates in the coordinates element (note that you don't need the "LookAt" element, but it will bring your camera to the relevant area):
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>LineString.kml</name>
<open>1</open>
<LookAt>
<longitude>-122.36415</longitude>
<latitude>37.824553</latitude>
<altitude>0</altitude>
<range>150</range>
<tilt>50</tilt>
<heading>0</heading>
</LookAt>
<Placemark>
<name>unextruded</name>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<coordinates>
-122.364383,37.824664,0 -122.364152,37.824322,0
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>extruded</name>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>
-122.364167,37.824787,50 -122.363917,37.824423,50
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
If you don't have the city altitudes then leave them out and be sure to set the altitudeMode element to "clampToGround" and likely the tesselate element to "1" (meaning true). If you forget this your lines may disappear underground.