I
I
Igor2019-12-21 13:12:41
API
Igor, 2019-12-21 13:12:41

Determining a point inside the Moscow Ring Road Yandex API?

Good afternoon, I ask for help with one function inPoly (x, y)
it incorrectly determines whether the address is inside the Moscow Ring Road, all addresses are determined as outside the Moscow Ring Road

function inPoly( x, y ){
  let j = mkad_points.length - 1,
    c = false; // true/false - внутри или вне полигона
  for (i = 0; i < mkad_points.length; i++){
    if ((((mkad_points[i][1]<=y) && (y<mkad_points[j][1])) || ((mkad_points[j][1]<=y) && (y<mkad_points[i][1]))) && (x > (mkad_points[j][0] - mkad_points[i][0]) * (y - mkad_points[i][1]) / (mkad_points[j][1] - mkad_points[i][1]) + mkad_points[i][0])) {
      c = !c
    		}
    	j = i;
  	}
  return c;
}

array of MKAD points
let mkad_points =  [
    [55.78000432402266,37.84172564285271],
    [55.775874525970494,37.8381207618713],
    [55.775626746008065,37.83979446823122],
    [55.77446586811748,37.84243326983639],
    ..........
    [55.79131399999368,37.840581150787344],
    [55.78000432402266,37.84172564285271]
    ];

All mkad_points coordinates do not fit (they are at the link pastebin.com/raw/DKgMrxqF)
Coordinates of a point inside the Moscow Ring Road 37.499893 55.718872
If I pass them to the inPoly (x, y ) function, I get false
Even if I take the last 55.78000432402266,37.84172564285271 from mkap_point, for example,
and pass it to the function still false

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor, 2019-12-21
@peretc001

Ops, remove the question, incorrectly transmitted the coordinates of the point))
inPoly (55.718872, 37.499893) - correct

P
Pavel, 2021-09-06
@pavelBer

Good afternoon! Maybe you still have a copy (they are at the link pastebin.com/raw/DKgMrxqF)? I do the same thing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question