/    Sign up×
Community /Pin to ProfileBookmark

Measuring distance on line

People is there anybody who has worked with maps. I need to measure a street distance on a web map using javascript (this web map is like an image – so all clicks are like image clicks). The problem is I can measure from two points (straight line with two ends) but when it comes to street lines with more that one segments I’m batling. I know it can be done probably using mouse events (one first mouse click, on mouse move, on mouse click and on mouse double click). The problem is more complicated by the fact that the map has other image buttons of which tells the web map what to happen to it: one of those buttons images is the measure distance button. Others are zoom in button(working), zoom out (working) and pan button(working).

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@GollumOct 02.2003 — What are you trying to do?

- Get the user to trace their path on the map and follow the mouse moves?

or take the user's start and end points and work out the distance somehow?

The first option isn't too hard, you just catch the onmousemove event and compare the last x,y position with the current one and add that to a running total.

The second is more complicated. Javascript cannot interpret images in any way, you will need to provide geometric data about the streets in addition to the image to be able to work out the distances.
Copy linkTweet thisAlerts:
@ThabaniauthorOct 02.2003 — Thank you

Gollum

Actualy "your" first question is more like it. I was just cought in the mist of trying to explain it. Okay, I think I got it. basically create a point object and the use the push/pop() to all your coordinates into an array. that way you can not only get the total distance at once but also get tot draw a line for ur route and still have all ur source data in an array.

Thanx a lot.
×

Success!

Help @Thabani spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...