Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating other geo-encoders (such as photon) (code example included) #224

Open
Zzz-ams opened this issue Oct 31, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@Zzz-ams
Copy link

Zzz-ams commented Oct 31, 2024

Description

What kind of feature you are suggesting?

Supporting other geo encoders, such as photon.

Does it solve any problem?

That this frontend is not bound to only use nominatim as a geo encoder.
An alternative improvement might be improving search results in case one of the geo encoders does not give back any results.

Questions

What do you think the best way to integrate multiple geo encoders would be?
In a way that based on environment variables only the correct one is imported or used?

(ps: example photon.js works)

Example utils/photon.js :

import axios from 'axios'

export const PHOTON_URL = `${process.env.REACT_APP_PHOTON_URL}/api`
export const PHOTON_URL_REVERSE = `${process.env.REACT_APP_PHOTON_URL}/reverse`

export const forward_geocode = (userInput) =>
  axios.get(PHOTON_URL, {
    params: {
      // eslint-disable-next-line
      q: userInput,
      limit: 5,
    },
  })

export const reverse_geocode = (lon, lat) =>
  axios.get(PHOTON_URL_REVERSE, {
    params: {
      lon: lon,
      lat: lat,
    },
  })

export const parseGeocodeResponse = (results, lngLat) => {
  results = results.features
  const processedResults = []
  for (const [index, result] of results.entries()) {
    if (
      'error' in result &&
      result.error.toLowerCase() === 'unable to geocode'
    ) {
      processedResults.push({
        title: lngLat.toString(),
        description: '',
        selected: true,
        addresslnglat: '',
        sourcelnglat: lngLat,
        displaylnglat: lngLat,
        key: index,
        addressindex: index,
      })
    } else {
      processedResults.push({
        title:
          result.properties.name.length > 0
            ? result.properties.name
            : lngLat.toString(),
        description: `https://www.openstreetmap.org/${result.properties.osm_type}/${result.properties.osm_id}`,
        selected: false,
        addresslnglat: [
          parseFloat(result.geometry.coordinates[0]),
          parseFloat(result.geometry.coordinates[1]),
        ],
        sourcelnglat:
          lngLat === undefined
            ? [
                parseFloat(result.geometry.coordinates[0]),
                parseFloat(result.geometry.coordinates[1]),
              ]
            : lngLat,
        displaylnglat:
          lngLat !== undefined
            ? lngLat
            : [
                parseFloat(result.geometry.coordinates[0]),
                parseFloat(result.geometry.coordinates[1]),
              ],
        key: index,
        addressindex: index,
      })
    }
  }
  return processedResults
}

Screenshots

No response

Additional information

No response

@Zzz-ams Zzz-ams added the enhancement New feature or request label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant