Hi

I am hoping someone can help me I have a map that plots a route and has
polylines snapping to the nearest street. This can be seen here:

http://www.cycleit.net/maps

The latitude and longitude points is showing on the sidebar for each point
that I click. The next stage I want to be able to do is save this data to an
XML file, but not sure how to go about doing this I was wondering if someone
can help me with this.

P.S just in case here is my JS code ive written so far for this:

var map, geocoder = null;
var centerLatitude = 53.871963457471786;
var centerLongitude = -4.669189453125;
var startZoom = 7;
var deselectCurrent = function() {};
var latlngs = [];


function initializePoint(id) {
    var marker = new GMarker(latlngs[id], { draggable:true });
    var listItem = document.createElement('li');
    var listItemLink = listItem.appendChild(document.createElement('a'));
    listItemLink.href = "#";
    listItemLink.innerHTML = '<strong>' + latlngs[id].lat() + '<br />' +
latlngs[id].lng() + '</strong>';

    var focusPoint = function() {
        deselectCurrent();
        listItem.className = 'current';
        deselectCurrent = function() { listItem.className = ''; }
        map.panTo(latlngs[id]);
        return false;
    }

    GEvent.addListener(marker, 'click', focusPoint);
    listItemLink.onclick = focusPoint;

    document.getElementById('sidebar-list').appendChild(listItem);
}

function handleMapClick(marker, latlng) {
    if (!marker) {
        latlngs.push(latlng);
        initializePoint(latlngs.length - 1);
    }
}

function windowHeight() {
    // Standard browsers (Mozilla, Safari, etc.)
    if (self.innerHeight)
        return self.innerHeight;
    // IE 6
    if (document.documentElement && document.documentElement.clientHeight)
        return document.documentElement.clientHeight;
    // IE 5
    if (document.body)
        return document.body.clientHeight;
    // Just in case.
    return 0;
}

function handleResize() {
    var height = windowHeight() -
document.getElementById('toolbar').offsetHeight - 30;
    document.getElementById('map').style.height = height + 'px';
    document.getElementById('sidebar').style.height = height + 'px';
}

function changeBodyClass(from, to) {
     document.body.className = document.body.className.replace(from, to);
     return false;
}

function init() {
    _mSvgEnabled = false; // Firefox 1.5.0.4/Mac wasn't rendering the SVG.

    document.getElementById('button-sidebar-hide').onclick = function() {
return changeBodyClass('sidebar-right', 'nosidebar'); };
    document.getElementById('button-sidebar-show').onclick = function() {
return changeBodyClass('nosidebar', 'sidebar-right'); };
    handleResize();

    map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(centerLatitude, centerLongitude),
startZoom);
    map.addControl(new GSmallMapControl());
    GEvent.addListener(map, 'click', handleMapClick);
    var dirn = new GDirections();
    var firstpoint = true;
    var gmarkers = [];
    var gpolys = [];
    var dist = 0;

    GEvent.addListener(map, "click", function(overlay,point) {
        // == When the user clicks on a the map, get directiobns from that
point to itself ==
        if (!overlay) {
          if (firstpoint) {

dirn.loadFromWaypoints([point.toUrlValue(6),point.toUrlValue(6)],{getPolyline:true});
          } else {

dirn.loadFromWaypoints([gmarkers[gmarkers.length-1].getPoint(),point.toUrlValue(6)],{getPolyline:true});
          }
        }
      });

       // == when the load event completes, plot the point on the street ==
      GEvent.addListener(dirn,"load", function() {
        // snap to last vertex in the polyline
        var n = dirn.getPolyline().getVertexCount();
        var p=dirn.getPolyline().getVertex(n-1);
        var marker=new GMarker(p);
        map.addOverlay(marker);
        // store the details
        gmarkers.push(marker);
        if (!firstpoint) {
          map.addOverlay(dirn.getPolyline());
          gpolys.push(dirn.getPolyline());
          dist += dirn.getPolyline().Distance();
          document.getElementById("distance").innerHTML="Path length:
"+(dist/1000).toFixed(2)+" km. "+(dist/1609.344).toFixed(2)+" miles.";
        }
        firstpoint = false;
      });

      GEvent.addListener(dirn,"error", function() {
        GLog.write("Failed: "+dirn.getStatus().code);
      });
}
window.onload = init;
window.onunload = GUnload;

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to