tags:

views:

56

answers:

1

If you go here: http://econym.org.uk/gmap/snap.htm there are some examples of the kind of stuff I'm trying to do. I want the user to enter a route on a google maps widget, and then have the map drawl the route along roads. Then the user click on a "submit" button, and their route is sent back to the server where it will be stored in a database.

img

Instead of sending back just the red vertices, I want to send back all the information that makes up the purple lines. Is this possible?

+2  A: 

Purple lines are polylines which are stored as an array under DOM.You can send their information into your server.

In this page,there is a javascript event triggers after you clicked on map as follows:

var firstpoint = true;
var gmarkers = [];
var gpolys = [];
var dist = 0;

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;
  });

These lines of code say that,after you clicked on map,the point you clicked snapped to nearest road,then if you add a second point to another point,a blue route appears as between all those polylines.
As I said previously,those polylines are stored in gpolys array.Also know that all vertices or GMarkers are also stored in gmarkers array.

Hope this helps
Myra

Myra