mercredi 31 octobre 2018

Laravel's contains() helper on Collection of associative arrays, searching with multiple arguments

I have this collection of precise GIS coordinates and I'm trying to find location matches by passing through both a lat and long using laravel's contains helper. Sample of collection as $points:

Polygon {#16091
  #points: array:103 [
    0 => Point {#719
      +x: -93.299203918246
      +y: 44.914451664177
    }
    1 => Point {#729
      +x: -93.299203946751
      +y: 44.914492803531
    }
    2 => Point {#737
      +x: -93.299203993418
      +y: 44.914561369423
    }
    3 => Point {#738
      +x: -93.299204049158
      +y: 44.914643647233
    }
  ]
}

My check is if ($points->contains($lng, $lat)) { // do something }. I'm not getting any matches, so just curious if I can even use contains() in this context? I know it works with a simpler collection. I tried hard-coding what would definitely be exact matches (pulled from the data set I am searching through) and it still returns false. Another issue I have, which I haven't even begun to address is that the coordinates that are coming from one query that sets $lat and $lng have 6 decimals (-93.208572) and the GIS data I'm searching through has coordinates with 12 decimals (44.174837264857). My understanding is that contains would still find matches, but I suppose I'll cross that bridge when I get there... I also tried to split the check up with key / value pairs:

$lngCheck = $points->contains('x', $lng);
$latCheck = $points->contains('y', $lat);

and then checking if they are both true for a match. I'm still always getting false.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire