Javascript to calculate possible routes between two points
Hi,
I need a help with a project I am working on.
I am not a developer so not so familiar with javascript.
Suppose I have a map with ten junctions and based on that map,
I need to calculate all the possible routes between one junction to another.
How do I represent the map in javascript and how do I code the function to calculate all the possible routes?? :-(
many thanks if someone can help me
thanks for the suggestion :-)
I actually did try that earlier, but their code was going above my head though.
I am not even as half technical as the others on this forum, which is why I needed a simple javascript code :-(
fair enough, but the problem is that it's not really a simple thing that you are trying to do.
if they are real junctions and real roads (or whatever the routes will be) some sort of maps API will be the simplest way to do this.
the problem with looking for "all the possible routes" is partially to do with logic - all the possibilities amount to a near infinite number, considering that going from your house to your next door neighbor's via China is one possible route.
so narrowing it down to "all the best routes" or even "the one best route per start and end point" is definitely going to help
if on the other hand the junctions are chosen by you (and will never change) and you can dictate the routes as well, it's as simple as drawing some lines on the map.
you are quite right :-)
My actual aim is to find all the "best routes" and in my case, the junctions are going to be defined by me and not going to change (may be if I want to add a new junction to the existing links, then probably I might have to add the routes too) and the routes are limited too !!
so how do I write a javascript function for this then
If you really want to write this yourself, the FIRST thing you should do is sit down with pencil and paper, draw the node map, and then figure out how you would get the answer by hand.
*THEN* convert your mental methodology to code.
If you can't express the solution in human terms, you can't write the code.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
this displays two route options between the same start and end points
this is a point and click tool that creates code that you can use in google maps to show lines on the map (note that one option that you can select is "directions"
if you have your junctions defined (and know which routes you want to display), it would seem to me to be easier to use the second one and hardcode the lines onto your page (or in an external DB) rather than making repeated calls to the directions service
xelawho: I could be wrong, but I strongly suspect this is homework. An exercise in program design and problem solving. I doubt that he needs any graphical representation (that is, any map) at all. Don't be surprised if he uses prompt() and document.write() to present the answer.
But we shall see.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
xelawho: I could be wrong, but I strongly suspect this is homework.
In this case either he is enrolled in a high level programming class (which I doubt) or his teacher uses to give his students laborious homework to do.
The problem is rather intricate, even if the paths are straight lines. But if they are curves, one might need to use interpolations and integral calculations to solve it. I doubt it can be solved with a couple of prompts and several elementary lines of codes.
I am going through the tutorial given by GOOS.
Very helpful indeed :-)
yea this project is for my final semster in college / school whatever you call it
thanks everyone..
will bug you all again if I get stuck somewhere :P