Here's my function to compare the polylines, pointsPoly is my
waypoints array & directionPoly was returned with gDirections.
function compare_polylines() {
var pointsVertices = pointsPoly;
var directionsVertices = directionsPoly.g;
var curveToLineRatio = 2;
var firstPoint = pointsVertices[0];
bestPoints.push(firstPoint);
var directionsIndex = 0;
for (var i=1; i<pointsVertices.length; i++) {
secondPoint = pointsVertices[i];
lineDistance = firstPoint.distanceFrom(secondPoint);
curveStart = curveEnd = curveDistance = 0;
foundStart = foundEend = false;
for (var j=directionsVertices.length-1; j>=directionsIndex ;
j--) {
if ((Math.abs(directionsVertices[j].lat() -
firstPoint.lat()) < 0.0006) && (Math.abs(directionsVertices[j].lng() -
firstPoint.lng())) < 0.0006) {
curveStart = j;
foundStart = true;
}
if ((Math.abs(directionsVertices[j].lat() -
secondPoint.lat()) < 0.0006) && (Math.abs(directionsVertices[j].lng() -
secondPoint.lng())) < 0.0006) {
curveEnd = j;
foundEend = true;
}
}
if (foundStart && foundEend) {
firstCurvePoint = directionsVertices[curveStart];
for (var j=curveStart+1;j<=curveEnd;j++) {
secondCurvePoint = directionsVertices[j];
curveDistance +=
firstCurvePoint.distanceFrom(secondCurvePoint);
firstCurvePoint = secondCurvePoint;
}
directionsIndex = curveEnd;
}
firstPoint = secondPoint;
if ((curveDistance > 0) && (curveDistance < (lineDistance *
curveToLineRatio))) {
curveRange = curveEnd - curveStart;
if (curveRange > 6) {
curveStep = Math.floor(curveRange/6)
} else {
curveStep = 1;
}
for (var j=curveStart;j<curveEnd;j+=curveStep) {
bestPoints.push(directionsVertices[j]);
}
} else {
bestPoints.push(secondPoint);
}
}
bestPoly = new GPolyline(bestPoints, {color:"#0000FF", weight:
5, opacity:0.45});
replay_from_polyline(bestPoly);
}
On Apr 23, 2:18 pm, Jeff <[email protected]> wrote:
> I made it work with the polyline made from the waypoints. Which goes
> off the road in some places, but doesn't go off on wild tangents.
>
> I was thinking if I got both polylines (one from directions & one
> contructed just from waypoints) and then compared the distance of
> segments between waypoints I might be able to choose the best segment
> for each pair of waypoints and construct a 3rd polyline that is the
> best of both worlds.
>
> Of coarse that goes beyond my current understanding of polylines.
>
> On Apr 23, 12:50 pm, "[email protected]" <[email protected]>
> wrote:
>
>
>
> > On Apr 23, 9:00 am, Jeff <[email protected]> wrote:
>
> > > Unless either or BOTH endpoints are on the wrong side of the road. I
> > > can't win. Thanks for your help.
>
> > But you could potentially use William's test to see if those 2 points
> > are on the correct side of the road or not.
>
> > Or maybe the direction of travel (which I think I remember you saying
> > you had) and a the direction of the first segment of the directions
> > polyline.
>
> > -- Larry
>
> > > On Apr 23, 11:11 am, "[email protected]" <[email protected]>
> > > wrote:
>
> > > > On Apr 23, 7:54 am, Jeff <[email protected]> wrote:
>
> > > > > Will the created polyline stay on the roads, or be a straight line
> > > > > between points? Also as part of my data set I have the direction of
> > > > > travel as a float from 0-360, can that be of use?
>
> > > > It will be a straight line between the points.
>
> > > > Probably your best option is to do end to end directions, then use the
> > > > resulting polyline as opposed to trying to do directions between the
> > > > individual points.
>
> > > > -- Larry
>
> > > > > On Apr 23, 10:36 am, "[email protected]" <[email protected]>
> > > > > wrote:
>
> > > > > > On Apr 23, 7:15 am, Jeff <[email protected]> wrote:
>
> > > > > > > I think our modems are 'supposed' to be accurate to 5 meters. He
> > > > > > > must
> > > > > > > have been in the passing lane when that particular reading was
> > > > > > > taken.
>
> > > > > > > Is there a way to generate a polyline other than using a
> > > > > > > GDirections
> > > > > > > object?
>
> > > > > > If you have the points you can create a polyline by passing it an
> > > > > > array of
> > > > > > GLatLngs:http://code.google.com/apis/maps/documentation/reference.html#GPolyli...
>
> > > > > > -- Larry
>
> > > > > > > On Apr 23, 10:02 am, William <[email protected]> wrote:
>
> > > > > > > > On Apr 23, 9:13 pm, Jeff <[email protected]> wrote:
>
> > > > > > > > > The waypoints are generated by a gps modem in a vehicle. I
> > > > > > > > > have no way
> > > > > > > > > of changing or correcting them.
>
> > > > > > > > It's not very practical but it's possible to use Google Maps
> > > > > > > > API to
> > > > > > > > calculate adjustments so the points are on the correct side of
> > > > > > > > the
> > > > > > > > divided highway.
>
> > > > > > > > The data has precision of 4 decimal places (about 10 metres),
> > > > > > > > so its
> > > > > > > > worth moving each point 0.00005 degrees to the North, South,
> > > > > > > > East and
> > > > > > > > West, to see if that reduces the distance to the next waypoint.
>
> > > > > > > > The following map shows how it might work, illustrating the
> > > > > > > > points
> > > > > > > > which are the wrong side of the freeway:
>
> > > > > > > >http://www.william-map.com/20100423/1/map.htm
>
> > > > > > > > ...
>
> > > > > > > > --
> > > > > > > > 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
> > > > > > > > athttp://groups.google.com/group/google-maps-api?hl=en.
>
> > > > > > > --
> > > > > > > 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
> > > > > > > athttp://groups.google.com/group/google-maps-api?hl=en.-Hidequotedtext-
>
> > > > > > > - Show quoted text -
>
> > > > > > --
> > > > > > 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
> > > > > > athttp://groups.google.com/group/google-maps-api?hl=en.
>
> > > > > --
> > > > > 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
> > > > > athttp://groups.google.com/group/google-maps-api?hl=en.-Hidequotedtext-
>
> > > > > - Show quoted text -
>
> > > > --
> > > > 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
> > > > athttp://groups.google.com/group/google-maps-api?hl=en.
>
> > > --
> > > 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
> > > athttp://groups.google.com/group/google-maps-api?hl=en.-Hidequoted text -
>
> > > - Show quoted text -
>
> > --
> > 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
> > athttp://groups.google.com/group/google-maps-api?hl=en.
>
> --
> 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
> athttp://groups.google.com/group/google-maps-api?hl=en.
--
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.