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

  • SEARCH
  • Home
  • 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 7755057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:28:18+00:00 2026-06-01T12:28:18+00:00

I have set up a sample polyline with five segments , and I’m allowing

  • 0

I have set up a sample polyline with five segments, and I’m allowing new markers to be created when the user clicks on the polyline.

I’d like to know if there’s a foolproof way to determine whether the new marker is between markers 0 and 1, or 1 and 2 … or between 4 and 5. I’ve considered checking if the new marker is inside a bounding box, and point-in-line formulas, but neither is 100% precise.

  • 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-06-01T12:28:19+00:00Added an answer on June 1, 2026 at 12:28 pm

    As Google Maps uses Mercator Projection for projecting GPS coordinates, you can’t use ‘line equation’ for gps coordinates, because projection is not linear for gps points.But instead you can use world coordinates which are linear. Here I have used parametric form of line equation to check whether point on segment:

    function isPointOnSegment( map, gpsPoint1, gpsPoint2, gpsPoint ){
         var p1 = map.getProjection().fromLatLngToPoint( gpsPoint1 );
         var p2 = map.getProjection().fromLatLngToPoint( gpsPoint2 );
         var p = map.getProjection().fromLatLngToPoint( gpsPoint );
         var t_x;
         var t_y;
         //Parametric form of line equation is:
         //--------------------------------
         //      x = x1 + t(x2-x1)
         //      y = y1 + t(y2-y1) 
         //--------------------------------
         //'p' is on [p1,p2] segment,if 't' is number from [0,1]
         //-----Case 1----
         //      x = x1
         //      y = y1
         //---------------
         if( p2.x-p1.x == 0 && p2.y-p1.y == 0){
            return p.x == p1.x && p.y == p1.y;
         }else 
         //-----Case 2----
         //      x = x1
         //      y = y1 + t(y2-y1)
         //---------------
         if( p2.x-p1.x == 0 && p2.y-p1.y != 0){
            t_y = (p.y - p1.y)/(p2.y-p1.y);
            return p.x == p1.x && t_y >= 0 && t_y <= 1;
         }else
         //-----Case 3----
         //      x = x1 + t(x2-x1)
         //      y = y1 
         //---------------
         if( p2.x-p1.x != 0 && p2.y-p1.y == 0){
            t_x = (p.x - p1.x)/(p2.x-p1.x);
            return p.y == p1.y && t_x >= 0 && t_x <= 1;
         }
         //-----Case 4----
         //      x = x1 + t(x2-x1)
         //      y = y1 + t(y2-y1) 
         //---------------
         t_x = (p.x - p1.x)/(p2.x-p1.x);
         t_y = (p.y - p1.y)/(p2.y-p1.y);
         return ( t_x == t_y && t_x >= 0 && t_x <= 1 && t_y >= 0 && t_y <= 1);
    } 
    

    By having clicked point and all segments of polyline, you could use above implemented function and retrieve segment you were looking for.

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

Sidebar

Related Questions

I have a sample Rails 3.1.1 application that I have set devise up to
Say you have a string 3.4564. A sample set in the database has these
I've been experimenting with OpenID, and have set up a sample web page to
I have the following sample set of data: <p>first line\n second line\n third line\n</p>
I have a sample set of XML returned back: <rsp stat=ok> <site> <id>1234</id> <name>testAddress</name>
I have created one GUI using Swing of Java. I have to now set
Sample page On the sample page I have set div#content { padding-bottom:20px; } which
I have the following set of constraints in Perl (just a sample set of
I am using the map.fitbounds to fit all the markers I have set with
I'm trying out the new LayoutTransition class in Honeycomb. I have set an animation

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.