Search code examples
kmlgoogle-earth

Does KML support a search function


Is there a KML tag sequence which will position Google Earth to the specified location?

If I start Google Earth, type "Houston" in the search text box and press [Search], the map is positioned to Houston, Texas.

Can you accomplish this via KML?

If not, how would you go about doing this? I'm attempting to do this from a C# application.

Thanks!


Solution

  • Most basic KML files look something 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 of KML</name>
        <StyleMap>
        .........
        </StyleMap>
        <Folder>
        ......
        </Folder>
    </Document>
    

    If you assign a <LookAt> or <Camera> to the <Document> node, whenever the KML is loaded it should load that view - unless told otherwise (eg via API/COM)

    So your KML 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 of KML</name>
        <LookAt>
        ..........
        </LookAt>
        <StyleMap>
        .........
        </StyleMap>
        <Folder>
        ......
        </Folder>
    </Document>