Hi All,
I'm new to this community and not sure if this is the correct place to be. I have a need to create a json feed that will return 8 closest points from a given location on a feature layer. Using esri's javascript API I am able to query the feature layer, retrieve the points and display them in a pop-up window on the screen. Instead of displaying the results on the screen I would to send them to the browser as a JSON Object. Is this doable using ArcGIS JavaScript API or do I need to use another Esri API? Any advice/insights would be greatly appreciated.
Sounds like you want to create an API rather than a web app. Look into publishing a geoprocessing service.
Is this something that is available in Arcgis Online?
You can query the REST endpoint of a hosted feature layer in ArcGIS Online. However, there's no option to measure the distance from the input geometry. That would require a geoprocessing task of some kind. A quick search didn't reveal anything like that available in ArcGIS Online but I'm not that familiar with that stuff.
Here's an example hosted feature layer and here's a URL to query the first 8 records within 100 miles of the input geometry (point as lon/lat). Changing the f=pjson to f=html will let you see the all the query parameters available.
https://services7.arcgis.com/LXCny1HyhQCUSueu/arcgis/rest/services/Definitive_Healthcare_USA_Hospital_Beds/FeatureServer/0/query?where=1%3D1&objectIds=&time=&geometry=-90.270527%2C+38.637732&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=100&units=esriSRUnit_StatuteMile&returnGeodetic=false&outFields=&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=0&resultRecordCount=8&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&token=&f=pjson
This link might help with your gathering of the 8 closest results: https://community.esri.com/t5/arcgis-api-for-javascript/featurelayer-queryfeatures-order-by-closest-...