Search code examples
iosgoogle-earth

Can location or search parameters be passed to comgoogleearth:// in iOS?


If the Google Earth app is installed on an iPad (with iOS 4.2 or 5.0.1) a URL scheme link to comgoogleearth:// from an HTML document in Safari or a PDF in GoodReader will open the application.

Is there a way to provide a parameter to specify a location either as a search or as a file in .kml or .kmz? I have tried various syntax without any luck so far.

I already know how to open the location in the Google Maps application - using an http://maps.google.com/ link with appropriate search parameters that is "hijacked" to the Maps app instead of the web site.

I would like to do the same sort of thing with Google Earth if possible.


Solution

  • Not directly no, to date the Apple application protocol for Google Earth doesn't support any kind of query.

    NSString *stringURL = @"comgoogleearth://";
    NSURL *url = [NSURL URLWithString:stringURL];
    [[UIApplication sharedApplication] openURL:url]
    

    However you could achieve the functionality you require indirectly with a CGI script on a publicly accessible server pretty easily.

    1) Create a CGI script that will accept a given latitude and longitude and create a simple KmlPlacemark with the given location.

    for example, in PHP:

    <?php
    // Get the latitude and longitude from the query
    if(is_numeric($_GET["lng"]) && is_numeric($_GET["lat"])) {
      $lng = $_GET["lng"];
      $lat = $_GET["lat"];
    } else {
      exit();
    }
    
    // Creates an array of strings to hold the lines of the KML file.
    $kml = array('<?xml version="1.0" encoding="UTF-8"?>');
    $kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';
    $kml[] = ' <Document>';
    $kml[] = '   <Placemark id="">';
    $kml[] = '   <Point>';
    $kml[] = '   <coordinates>' . $lng . ','  . $lat . '</coordinates>';
    $kml[] = '   </Point>';
    $kml[] = '   </Placemark>';
    $kml[] = ' </Document>';
    $kml[] = '</kml>';
    $kmlOutput = join("\n", $kml);
    header('Content-type: application/vnd.google-earth.kml+xml');
    echo $kmlOutput;
    ?>
    

    2) Call the Apple application protocol for Google Earth using a url to the CGI script we created that supplies the required coordinates. e.g.

    comgoogleearth://www.yourserver.com/kmlScript.php?lng=53.2&lat=34.34
    

    When the URL is loaded the Google Earth app will fly to the location.

    This method can be used to generate a location from a search (geocoding) with a slight modification easily.

    The only limitation to this is that the IOS device must be able to access the server holding the CGI script (won't work off-line)