Public feed
#379285
<script type="text/JavaScript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var geocoder = new GClientGeocoder();
//var mgrOptions = { maxZoom: 15 };
//var mgr = new GMarkerManager(map, mgrOptions);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var data = new Array();
var counter=0;
//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
function showAddress(address) {
geocoder.getLatLng(
address,
function(point) {
store_point(address, point);
}
);
}
function getCoords() {
GLatLng(data[address]);
}
// create the array of ports of call.
var ports = new Array()
ports[0] = "Perth, Western Australia, Australia"
ports[1] = "Fremantle, Western Australia, Australia"
// loop through each port, passing the port name to showAddress function.
for (i=0;i<ports.length;i++)
{
var portName = ports[i];
showAddress(portName);
}
}
function store_point(address, point) {
// count how many elements we put in our associative array.
counter+=1;
// Store the point in array 'data' keyed by address.
data[address] = point;
// when the number of ports matches the times we've been through this function, we have all the data we need.
if ( ports.length == counter) {
plotMapData(data);
}
}
function plotMapData(data) {
var polylineData='';
// mark each port on the map
for (i=0;i<ports.length;i++) {
map.setCenter(data[ports[i]], 13);
var marker = new GMarker(data[ports[i]]);
map.addOverlay(marker);
marker.openInfoWindowHtml(ports[i]);
polylineData += 'new GLatLng'+data[ports[i]]+', ';
}
// strip the trailing comma from our polylineData string.
var stringLength=polylineData.length-2;
var polylineData=polylineData.substring(0, stringLength);
// draw the line
var polyline = new GPolyline([polylineData], "#FF0000", 10);
map.addOverlay(polyline);
}
}
//]]>
</script>