How can I move a map saved on Google Earth (.kml file) to a website using the Google Maps API?
December 7, 2005 3:14 PM
Subscribe
How can I export a map from Google Earth to a website using the Google Maps API?
I've plotted my worldly travels in GoogleEarth and would like to do the same on a website using Google Maps. I figure saving as KML is a good start, but I'm not sure what the next step is. Thanks for the help!
posted by JudgeBork to computers & internet (6 comments total)
The basic code for generating the map is located inside the body.onload function:
function onLoad() {
var map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.centerAndZoom(new GPoint(2.308588,48.873804), 3);
map.setMapType( _SATELLITE_TYPE );
The first line creates the map in the DIV holder called "map". The second line adds the zoom controls. The third line is where the map is centered (longitude and latitude) and how much it's zoomed in (level 3). The fourth line tells the map to start with the satellite map. You can change these to whatever you like. Check out the full Google Maps documentation for more information.
To create markers, use this function:
function createMarker(point, marktext) {
var marker = new GMarker(point);
var html = marktext;
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
Now you just need to load up all your points:
var markers = [];
var points = [];
points.push(new GPoint( 2.271252,48.869450));
points.push(new GPoint( 2.274277,48.871229));
points.push(new GPoint( 2.275103,48.871102));
markers.push(createMarker(points[0], "First point"));
markers.push(createMarker(points[1], "Second point"));
markers.push(createMarker(points[2], "Third point"));
Finally, add the markers as overlays to the map:
for (x=0; x < markers.length; x++) {br> map.addOverlay(markers[x]);
}
Then, just place somewhere inside the BODY part of your html a div called 'map' (you can call it whatever you like, of course).
<div id="map" style="width:600px; height: 500px;"></div>
You can view the HTML source code in my "rendezvous" map for a simple example.>
posted by Civil_Disobedient at 4:13 PM on December 7, 2005