Reputation: 5483
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?
Upvotes: 3
Views: 2960
Reputation: 20313
To display kml on google earth we have three methods:
1.From kml networklink
2.fetching data from url
3.fetching data from kml string
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.
NOTE: If you have so many placemarks then increase your altitude or else go for dynamic kml generation using server-side code with high altitude.Hope this helps you :-)
Upvotes: 1