I am trying to get the nearest farmers (points) to a specific customer (point). I made a buffer to this customer and then used turf-inside to get the points inside the buffer, but it doesn't work and I get this error:
Uncaught Error: A coordinate, feature, or point geometry is required
Here is my code
$.ajax({
type:"POST",
url:"CustomerID_geojson.php",
data:{'Cust_Name': Cust_Name} ,
dataType: 'json',
success: function (response) {
var unit = 'kilometers'
var buffered = turf.buffer(response, distance, unit)
$.ajax({
type: "POST",
url: 'allfarmers_geojson.php',
dataType: 'json',
success: function (data) {
var ptsWithin = turf.inside(data, buffered);
geojsonLayer = L.geoJson(ptsWithin).addTo(mymap);
mymap.fitBounds(geojsonLayer.getBounds());
}
})
}
})
Have a look at turf.inside
docs and signature:
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon.
Parameters
point (
Feature<Point>)
input pointpolygon (
Feature<(Polygon | MultiPolygon)>)
input polygon or multipolygon
You might rather be interested in turf.within
instead.
Original answer:
That error message complains that either your response
or data
is not a valid argument for turf.buffer
or turf.inside
respectively. Please output the content of those variables and make sure they comply with what Turf expects.