<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Custom Javascript - Based on Lat long from Geopoint return Segment ID in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/custom-javascript-based-on-lat-long-from-geopoint/m-p/1405373#M55957</link>
    <description>&lt;P&gt;Below is the java script but trying to pull a "label" of a line segment saved in a json file by the nearest point in a geopoint question using the geopoint lat long it keeps returning [object Object]&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Fetches 'geojson' data from a file&lt;BR /&gt;* @param {string} url - File url&lt;BR /&gt;* @returns {Promise&amp;lt;Object&amp;gt;} Promise resolving to 'geojson' data&lt;BR /&gt;*/&lt;BR /&gt;async function fetchGeoJsonData(url);&lt;BR /&gt;const response = await fetch(url);&lt;BR /&gt;if (!response.ok) {&lt;BR /&gt;throw new Error('Failed to fetch 'geojson' data');&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return response.json();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;export { fetchGeoJsonData };&lt;BR /&gt;// math.js&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Calculates distance between two points&lt;BR /&gt;* @param {number} lat1 - Point 1 latitude&lt;BR /&gt;* @param {number} lon1 - Point 1 longitude&lt;BR /&gt;* @param {number} lat2 - Point 2 latitude&lt;BR /&gt;* @param {number} lon2 - Point 2 longitude&lt;BR /&gt;* @returns {number} Distance between points&lt;BR /&gt;*/&lt;BR /&gt;export function calculateDistance(lat1, lon1, lat2, lon2) {&lt;BR /&gt;// distance calculation logic&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Finds the closest point on a segment to a given point&lt;BR /&gt;* @param {number} x0 - Point x&lt;BR /&gt;* @param {number} y0 - Point y&lt;BR /&gt;* @param {number} x1 - Segment point 1 x&lt;BR /&gt;* @param {number} y1 - Segment point 1 y&lt;BR /&gt;* @param {number} x2 - Segment point 2 x&lt;BR /&gt;* @param {number} y2 - Segment point 2 y&lt;BR /&gt;* @returns {Object} Object with x and y of closest point&lt;BR /&gt;*/&lt;BR /&gt;export function findClosestSegmentPoint(x0, y0, x1, y1, x2, y2) {&lt;BR /&gt;// find closest logic&lt;BR /&gt;return {&lt;BR /&gt;x: closestX,&lt;BR /&gt;y: closestY&lt;BR /&gt;};&lt;BR /&gt;}&lt;BR /&gt;// geo.js&lt;/P&gt;&lt;P&gt;import { fetchGeoJsonData } from './data.js';&lt;BR /&gt;import { calculateDistance, findClosestSegmentPoint } from './math.js';&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Finds the closest line segment to a point in geojson data&lt;BR /&gt;*/&lt;BR /&gt;export async function findNearestSegment(point, geojsonUrl) {&lt;/P&gt;&lt;P&gt;const geoData = await fetchGeoJsonData(geojsonUrl);&lt;/P&gt;&lt;P&gt;// Find closest logic using imported math functions&lt;/P&gt;&lt;P&gt;return nearestSegment;&lt;BR /&gt;}&lt;BR /&gt;// index.js&lt;/P&gt;&lt;P&gt;import { findNearestSegment } from './geo.js';&lt;/P&gt;&lt;P&gt;const point = {&lt;BR /&gt;lat: 0,&lt;BR /&gt;lon: 0&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;const geojsonUrl = 'data.json';&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;const nearest = await findNearestSegment(point, geojsonUrl);&lt;BR /&gt;console.log('Nearest segment:', nearest);&lt;BR /&gt;} catch (err) {&lt;BR /&gt;console.error('Error finding nearest segment', err);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2024 18:26:00 GMT</pubDate>
    <dc:creator>SteveBrewer</dc:creator>
    <dc:date>2024-04-03T18:26:00Z</dc:date>
    <item>
      <title>Custom Javascript - Based on Lat long from Geopoint return Segment ID</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/custom-javascript-based-on-lat-long-from-geopoint/m-p/1405373#M55957</link>
      <description>&lt;P&gt;Below is the java script but trying to pull a "label" of a line segment saved in a json file by the nearest point in a geopoint question using the geopoint lat long it keeps returning [object Object]&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Fetches 'geojson' data from a file&lt;BR /&gt;* @param {string} url - File url&lt;BR /&gt;* @returns {Promise&amp;lt;Object&amp;gt;} Promise resolving to 'geojson' data&lt;BR /&gt;*/&lt;BR /&gt;async function fetchGeoJsonData(url);&lt;BR /&gt;const response = await fetch(url);&lt;BR /&gt;if (!response.ok) {&lt;BR /&gt;throw new Error('Failed to fetch 'geojson' data');&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return response.json();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;export { fetchGeoJsonData };&lt;BR /&gt;// math.js&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Calculates distance between two points&lt;BR /&gt;* @param {number} lat1 - Point 1 latitude&lt;BR /&gt;* @param {number} lon1 - Point 1 longitude&lt;BR /&gt;* @param {number} lat2 - Point 2 latitude&lt;BR /&gt;* @param {number} lon2 - Point 2 longitude&lt;BR /&gt;* @returns {number} Distance between points&lt;BR /&gt;*/&lt;BR /&gt;export function calculateDistance(lat1, lon1, lat2, lon2) {&lt;BR /&gt;// distance calculation logic&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Finds the closest point on a segment to a given point&lt;BR /&gt;* @param {number} x0 - Point x&lt;BR /&gt;* @param {number} y0 - Point y&lt;BR /&gt;* @param {number} x1 - Segment point 1 x&lt;BR /&gt;* @param {number} y1 - Segment point 1 y&lt;BR /&gt;* @param {number} x2 - Segment point 2 x&lt;BR /&gt;* @param {number} y2 - Segment point 2 y&lt;BR /&gt;* @returns {Object} Object with x and y of closest point&lt;BR /&gt;*/&lt;BR /&gt;export function findClosestSegmentPoint(x0, y0, x1, y1, x2, y2) {&lt;BR /&gt;// find closest logic&lt;BR /&gt;return {&lt;BR /&gt;x: closestX,&lt;BR /&gt;y: closestY&lt;BR /&gt;};&lt;BR /&gt;}&lt;BR /&gt;// geo.js&lt;/P&gt;&lt;P&gt;import { fetchGeoJsonData } from './data.js';&lt;BR /&gt;import { calculateDistance, findClosestSegmentPoint } from './math.js';&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Finds the closest line segment to a point in geojson data&lt;BR /&gt;*/&lt;BR /&gt;export async function findNearestSegment(point, geojsonUrl) {&lt;/P&gt;&lt;P&gt;const geoData = await fetchGeoJsonData(geojsonUrl);&lt;/P&gt;&lt;P&gt;// Find closest logic using imported math functions&lt;/P&gt;&lt;P&gt;return nearestSegment;&lt;BR /&gt;}&lt;BR /&gt;// index.js&lt;/P&gt;&lt;P&gt;import { findNearestSegment } from './geo.js';&lt;/P&gt;&lt;P&gt;const point = {&lt;BR /&gt;lat: 0,&lt;BR /&gt;lon: 0&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;const geojsonUrl = 'data.json';&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;const nearest = await findNearestSegment(point, geojsonUrl);&lt;BR /&gt;console.log('Nearest segment:', nearest);&lt;BR /&gt;} catch (err) {&lt;BR /&gt;console.error('Error finding nearest segment', err);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 18:26:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/custom-javascript-based-on-lat-long-from-geopoint/m-p/1405373#M55957</guid>
      <dc:creator>SteveBrewer</dc:creator>
      <dc:date>2024-04-03T18:26:00Z</dc:date>
    </item>
  </channel>
</rss>

