Hi to all!
Well, I''ve been trying to find a solution to route using known LatLng
points
- I already have the location position, all I needed was the actual route,
so I''ve put together an addition to the
"mapstraction-route.js". I''ve listed
it below, so maybe it would not be a bad idea to merge it to the trunk...
Also, I have a few other questions regarding the routing:
1) How to handle errors when the route is unknown?
* namely, when I use the coordinates from the
http://mapstraction.com/route.php?router=mapquest&map=mapquest example,
everything works fine, but when I use [42.426474, -83.492817] and
[42.279092, -83.764378], i get the "TypeError: this.location has no
properties"
* I''m not really sure it is Mapstraction error, but here it is, so if
anyone
can help....
2) MapstractionRouter.prototype.addAPI = function(api)
* one has to manually set " ProxyServerPath " to something appropriate
to
the proxy solution used (the one in the example is for PHP and I work with
Rails)
* anyway, it would be nice to overload that parameter in the API itself (so
one does not need to change the code of the "mapstraction-route.js"
when
getting the new version
OK, that is it for now, any help regarding these question appreciated!
Vanja
/**
* Performs a routing and then calls the specified callback function with
the waypoints and route
* @param {Array} addresses The array of point/location objects to use for
the route
*/
MapstractionRouter.prototype.routePoints = function(points) {
var api = this.api;
switch (api) {
case ''mapquest'':
var waypoints = new MQLocationCollection();
var routeOptions = new MQRouteOptions();
for (var i=0;i<points.length;i++) {
var geoAddr = new MQGeoAddress();
geoAddr.setMQLatLng(new
MQLatLng(points[i].lat, points[i].lng));
waypoints.add(geoAddr);
}
var session = new MQSession();
var routeResults = new MQRouteResults();
var routeBoundingBox = new MQRectLL(new
MQLatLng(),new MQLatLng());
var sessId this.routers[api].createSessionEx(session);
this.routers[api].doRoute(waypoints,routeOptions,routeResults,sessId,routeBo
undingBox);
var routeParameters = new Array();
routeParameters[''results''] = routeResults;
routeParameters[''bounding_box''] = routeBoundingBox;
routeParameters[''session_id''] = sessId;
this.callback(points, routeParameters);
break;
default:
alert(api + '' not supported by mapstraction-router'');
break;
}
}