I have a map service hosted locally on my ArcGIS server with the location of all the fire hydrants in my city. I want to know if there's a way to find the nearest hydrant to the location I click on the map. Or to search for a hydrant within 50 meters.
Solved! Go to Solution.
You could use GeometryEngine to create a 50m buffer around your point, then query the table with the hydrants (ie the Url to you mapservice + "/" + the layer id). Something along the lines of:
var searchPolygon = GeometryEngine.BufferGeodetic(clickPoint, 50, LinearUnits.Meters);
var table = new ServiceFeatureTable(new Uri("https://PathToFireHydrantSubLayer"));
var hydrants = await table.QueryFeaturesAsync(new QueryParameters() { Geometry = searchPolygon });
You could use GeometryEngine to create a 50m buffer around your point, then query the table with the hydrants (ie the Url to you mapservice + "/" + the layer id). Something along the lines of:
var searchPolygon = GeometryEngine.BufferGeodetic(clickPoint, 50, LinearUnits.Meters);
var table = new ServiceFeatureTable(new Uri("https://PathToFireHydrantSubLayer"));
var hydrants = await table.QueryFeaturesAsync(new QueryParameters() { Geometry = searchPolygon });
...And if you would like to know actual travel distance/time then I suggest taking a look at the following samples:
- Find closest facility to an incident (interactive) | ArcGIS for Developers
- Find service area | ArcGIS for Developers
Cheers
Mike