Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:25:28+00:00 2026-05-27T14:25:28+00:00

Ok, I have an application that uses a mapping system to draw lines. Each

  • 0

Ok, I have an application that uses a mapping system to draw lines. Each line A,B is defined in lat/lon format. When a user clicks the map, all that is given to me is a single point, C, where the user clicked in lat/lon format. I want to give the user the ability to select lines on the map by clicking. The problem is, because of varying zoom levels, it is very difficult for a user to click exactly along the line. The best I can hope for is that they click within some threshold distance that I define. How can I figure out that the user has clicked on, or reasonably close to a line given only this information?

I have a rough idea for an algorithm but I haven’t fleshed it out, and I’m not sure if it’s the most efficient way to do it. Since there are potentially many lines on the screen at any time, the algorithm needs to be fairly quick.

What I’ve come up with so far is to first check the distance AC and BC. If either distance is greater than AB, then the user did not click on the line. If it passes this check, then I calculate angles CAB and CBA. If C is exactly on the line, then both angles should be 0, i think, my trig is kind of rusty. Otherwise, to determine if C is “close enough”, I will select the smallest of the two calculated angles, and see if it falls below some predefined threshold.

Am I on the right track or way off? Any better ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:25:29+00:00Added an answer on May 27, 2026 at 2:25 pm

    You may also directly calculate the distance of your point to any line. The wikipedia article gives you the details and also some (pseudo)code.

    In your case you also have to consider the end-points separately. I.e. you first have to calculate the parameter t (see article above) and check if it is within the range 0 to length of AB. Then if additionaly the distance lies below a pre-defined amount then the user did click on the line, otherwise not.

    The formulas in your case look as follows:

    (C - (A + t * (B-A))) * (B-A) = 0
    
    => t = (C.x - A.x) * (B.x - A.x) + (C.y - A.y) * (B.y - A.y) / ((B.x - A.X) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y))
    

    If t is below 0 or above 1 the user did not click on the line. Otherwise (i.e. t is between zero and one) you can calculate the distance d using this value t:

    d = dist(C, A+t*(B-A)) = sqrt( (C.x - A.x - t * (B.x - A.x))^2 + (C.y - A.y - t * (B.y - A.y))^2) 
    

    If d is below some pre-defined threshold you can assume that the user clicked on your line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that uses a dual monitor setup - User A will
I have an application that uses the mmap system call, I was having an
I have an application that uses NHibernate as its ORM and sometimes it experiences
I have client application that uses WCF service to insert some data to backend
I have an application that uses the accelerometer. Sometimes, the application will launch without
I have an application that uses window.open() to generate dynamic popups. Unfortunately, I've had
I have an application that uses a cron like job to update a set
I have an application that uses DataTables to perform grouping, filtering and aggregation of
I have an application that uses simple sockets to pass some characters between two
I have an application that uses Ajax.Request and its onSuccess event handler in lots

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.