Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I would like to show multiple Placemarks by parsing a kml file. Please help, Im stuck for long days. As I see google earth desktop client works well for following kml code snippet
 
<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
      <Placemark>
        <name>Placemark2 from KML file</name>
        <Point>
          <coordinates>-122.448425,36.802907,0</coordinates>
        </Point>
      </Placemark>
      <Placemark>
        <name>Placemark2 from KML file</name>
        <Point>
          <coordinates>-122.448425,37.802907,0</coordinates>
        </Point>
      </Placemark>
    </Document>
    </kml>
 
Based on the above code snippet I tried by following to show multiple placemark at first look. But NO LUCK. I prefer to parse kml string instead of fetching a .kml file, kml file need to be publicly available and reachable by Google. Moreover by parsing kml string we can test it from localhost.
 
<script src="//www.google.com/jsapi?key=ABQIAAAA5El50zA4PeDTEMlv-sXFfRSsTL4WIgxhMZ0ZK_kHjwHeQuOD4xTdBhxbkZWuzyYTVeclkwYHpb17ZQ"></script>
<script type="text/javascript">
    var ge;
    var placemark;
    var object;
    google.load("earth", "1");
    function init() {
        google.earth.createInstance('map3d', initCB, failureCB);
    }
    function initCB(instance) {
        ge = instance;
        ge.getWindow().setVisibility(true);
        var kmlString = ''
                        + '<?xml version="1.0" encoding="UTF-8"?>'
                        + '<kml xmlns="http://www.opengis.net/kml/2.2">'
                        + '<Document>'
                        + '<Placemark>'
                            + '<name>Placemark1</name>'
                            + '<description>Some Descriptive text.</description>'
                            + '<Point>'
                            + '<coordinates>-122.448425,36.802907,0</coordinates>'
                            + '</Point>'
                        + '</Placemark>'
                        + '<Placemark>'
                            + '<name>Placemark2</name>'
                            + '<Point>'
                            + '<coordinates>-122.448425,37.802907,0</coordinates>'
                            + '</Point>'
                        + '</Placemark>'
                        + '</Document>'
                        + '</kml>';
 
        var kmlObject = ge.parseKml(kmlString);
        ge.getFeatures().appendChild(kmlObject);
        ge.getView().setAbstractView(kmlObject.getAbstractView());
    }
    function failureCB(errorCode) {
    }
    google.setOnLoadCallback(init);
</script>
<div id="map3d" style="border: 1px solid silver; height: 400px; width: 600px;">
</div>
 
If I add following camera tag in document then one Placemark is shown. All placemark can be shown by zoom out.
+ '<Camera>'
          + '<longitude>-122.448425</longitude>'
          + '<latitude>36.802907</latitude>'
          + '<altitude>100</altitude >'                             
          + '<tilt>10</tilt>'
          + '<heading>2.7</heading>'
      + '</Camera>'
 
Have any idea, How can I show mulitple placemark at first look?
Posted 2-Feb-12 1:36am
Comments
Shahdat Hosain at 2-Feb-12 7:18am
   
Yap, I have good idea
 
"By specifying altitude as 100 in your kml,onload google earth display -122.448425,36.802907 placemark with altitude as 100.So,increase your altitude then you can view all your placemarks.I tried in my machine with altitude as 1000000 .Two placemarks are visible onload of google earth."
 
For more details , see http://stackoverflow.com/q/9110798/942070

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 2 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100