Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2011, 04:38 PM   PM User | #1
itzombie
New to the CF scene

 
Join Date: Oct 2011
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
itzombie is an unknown quantity at this point
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
itzombie is offline   Reply With Quote
Old 10-18-2011, 05:24 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I would look at something like the google maps directions service - I think they have done most of the heavy lifting for you.
xelawho is offline   Reply With Quote
Old 10-18-2011, 05:58 PM   PM User | #3
itzombie
New to the CF scene

 
Join Date: Oct 2011
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
itzombie is an unknown quantity at this point
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 :-(
itzombie is offline   Reply With Quote
Old 10-18-2011, 06:13 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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.
xelawho is offline   Reply With Quote
Old 10-18-2011, 06:24 PM   PM User | #5
itzombie
New to the CF scene

 
Join Date: Oct 2011
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
itzombie is an unknown quantity at this point
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
itzombie is offline   Reply With Quote
Old 10-18-2011, 08:06 PM   PM User | #6
Goos
New Coder

 
Join Date: Apr 2011
Posts: 45
Thanks: 0
Thanked 11 Times in 11 Posts
Goos is an unknown quantity at this point
It's been quite a while since I read it, but chapter 7 of http://eloquentjavascript.net/contents.html explains a pathfinding algorythm seems to fit your aim.
Goos is offline   Reply With Quote
Users who have thanked Goos for this post:
itzombie (10-19-2011)
Old 10-18-2011, 08:42 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Old 10-19-2011, 03:29 AM   PM User | #8
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
some examples that may be of use:

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 is offline   Reply With Quote
Users who have thanked xelawho for this post:
itzombie (10-19-2011)
Old 10-19-2011, 04:06 AM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Old 10-19-2011, 04:15 AM   PM User | #10
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Quote:
Originally Posted by Old Pedant
I could be wrong, but I strongly suspect this is homework.
well, if that's true it would make me feel fine about continuing to be vaguely useful on his one...
xelawho is offline   Reply With Quote
Old 10-19-2011, 12:25 PM   PM User | #11
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Quote:
Originally Posted by Old Pedant View Post
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.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 10-20-2011, 07:59 AM   PM User | #12
itzombie
New to the CF scene

 
Join Date: Oct 2011
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
itzombie is an unknown quantity at this point
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
itzombie is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, map, route

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:21 AM.


Advertisement
Log in to turn off these ads.