Well, I have a Google Maps instance in which I have a TraceHandler. That let the user make lines by city map. With these lines I am using google DirectionsRoute service to generate a route. The service returns various information, entre elas the *overview_path. Containing all points of directions change in my route. With these points i create triangles as follow:
var triangle;
for (var indexerTrian = 0; indexerTrian < self.bounds.length; indexerTrian++) {
if (indexerTrian + 1 == self.bounds.length) break;
var maxLng = self.bounds[indexerTrian].lng() < self.bounds[indexerTrian + 1].lng() ? self.bounds[indexerTrian].lng() : self.bounds[indexerTrian + 1].lng();
var minLng = self.bounds[indexerTrian].lng() > self.bounds[indexerTrian + 1].lng() ? self.bounds[indexerTrian].lng() : self.bounds[indexerTrian + 1].lng();
var latLngSouthWest = new gMap.LatLng(self.bounds[indexerTrian].lat(), maxLng);
var latLngNorthEast = new gMap.LatLng(self.bounds[indexerTrian + 1].lat(), minLng);
triangle= new gMap.LatLngBounds(latLngSouthWest, latLngNorthEast);
self.triangles.push(triangle);
}
The third part of this routine use those triangles to bring points in the route. Some code:
//for each point
for (var i in result.page) {
stopPoint = result.page[i];
latLng = new gMap.LatLng(stopPoint.latitude, stopPoint.longitude);
//for each triangle
for (var iTrian = 0; iTrian < self.triangles.length; iTrian++) {
//this guy verify if the stopPoint is inside the triangle.
//if so. Drop it on map
if (self.triangles[iTrian].contains(latLng)) {
//this method just generate a Marker instance.
self.SetaMarkers(latLng, iconMarker, stopPoint.descricao, true);
counter++;
break;
}
//this is a DEBUG if who prints all points if my loop comes to
//end
else if ((iTrian + 1) == self.triangles.length) {
self.SetaMarkers(latLng, null, stopPoint.descricao, true);
//break;
}
}
}
This works good. No erros at execution. But for those triangles who I change de Longitude their .contains don’t work. It may be a bug.
Here is an image to demonstrate. I’m printing the triangles to debug: http://s7.postimage.org/ek3prgryj/Map.png As u guys can see in the image. The normal red marker is those stopPoint that is out of the bounds of all triangles. And those with a edited image is the stopPoints in the bounds of some triangle.
I have tried a lot of things already.. now im going to print the center of each triangle to see if it is where it must be.
Solved the problem using a circle of 25 meters after 25 meters of the route. Now I can let the user set the radius and it’s getting everyone.