Google Map can read KML/KMZ files, so you can share your data created in google earth with google map. This is handled by GGeoXml object.
Here’s an example how to view data from a kml/kmz file using google API
var map;
var geoXml;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(0,0));
geoXml = new GGeoXml(hostname + kmzfile, function() {
zoomToGeoXML(geoXml); // centering the map according to the kml data
});
}
}
//Zoom the map
function zoomToGeoXML(geoXml) {
var center = geoXml.getDefaultCenter();
var span = geoXml.getDefaultSpan();
var sw = new GLatLng(center.lat() - span.lat() / 2,
center.lng() - span.lng() / 2);
var ne = new GLatLng(center.lat() + span.lat() / 2,
center.lng() + span.lng() / 2);
var bounds = new GLatLngBounds(sw, ne);
map.setCenter(center);
map.setZoom(map.getBoundsZoomLevel(bounds));
map.addOverlay(geoXml);
}
This page outlines KML support in Google Maps and Google Maps for mobile.
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.