# @visual-framework/vf-location-nearest

> vf-location-nearest component

Latest version **1.0.3** (published 2025-02-25) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install @visual-framework/vf-location-nearest
pnpm add @visual-framework/vf-location-nearest
yarn add @visual-framework/vf-location-nearest
bun add @visual-framework/vf-location-nearest
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2025-02-25 |
| First published | 2020-09-03 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 41.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | VF |
| Maintainers | sandykadam, ebiwebdev, khawkins98, pacope92, bhushan-ebi |
| Keywords | fractal, component |

## Links

- npm: https://www.npmjs.com/package/@visual-framework/vf-location-nearest
- Issues: https://github.com/visual-framework/vf-core/issues
- npm.io page: https://npm.io/package/@visual-framework/vf-location-nearest

## Recent versions

- 1.0.3 (latest) — 2025-02-25
- 1.0.2 — 2021-10-14
- 1.0.1 — 2021-02-25
- 1.0.0 — 2020-11-16
- 1.0.0-alpha.1 — 2020-09-03

## README

# Nearest Location component

[![npm version](https://badge.fury.io/js/%40visual-framework%2Fvf-location-nearest.svg)](https://badge.fury.io/js/%40visual-framework%2Fvf-location-nearest)

## About

From a list of lat and long, this will use the browser geolcation API to select the nearest. It also provides a manual selection fallback and override.

## Usage

This component is purely JavaScript and relies on other components to provide UI and to consume the detected region.

This is an early version, some future improvements to be considered:

- Callback to observe detected locations to be used in other components
- Allowing "or" matches for content `data-vf-js-location-nearest-activation-target="locationOne, locationTwo"`
- Enabling the default while we wait for geodetection
- "Saving" a user's location when using the override

### JS

You should import this component in `./components/vf-component-rollup/scripts.js` or your other JS process:

```js
import { vfLocationNearest } from 'vf-location-nearest/vf-location-nearest';
// Or import directly
// import { vfLocationNearest } from '../components/raw/vf-location-nearest/vf-location-nearest.js';

// Configure an object of your locations to detect
// You should do this in your central JS (scripts.js) as appropriate
let vfLocationNearestLocations = {
  // supply a default in case of geodetect failures
  default: {
    name: "Heidelberg",
    latlon: "49.40768, 8.69079" // lat then lon
  },
  barcelona: {
    name: "Barcelona",
    latlon: "0.40768, 0.69079"
  },
  ...
  }
}
// Bootstrap location detection
vfLocationNearest(vfLocationNearestLocations);
```

### JS Data attributes

All are optional

- `data-vf-js-location-nearest-name` element will receive the name of the current location
- `data-vf-js-location-nearest-override-widget` element will be populated with an override widget (vf-form select list)
- `data-vf-js-location-nearest-activation-target="{locationId}"` will receive clicks on location change. This is a simple method to activate diverse elements.

## Install

This repository is distributed with [npm][https://www.npmjs.com/]. After [installing npm][https://www.npmjs.com/get-npm] and [yarn](https://classic.yarnpkg.com/en/docs/install), you can install `vf-location-nearest` with this command.

```
$ yarn add --dev @visual-framework/vf-location-nearest
```

## Help

- [Read the Visual Framework troubleshooting](https://stable.visual-framework.dev/troubleshooting/)
- [Open a ticket](https://github.com/visual-framework/vf-core/issues)
- [Chat on Slack](https://join.slack.com/t/visual-framework/shared_invite/enQtNDAxNzY0NDg4NTY0LWFhMjEwNGY3ZTk3NWYxNWVjOWQ1ZWE4YjViZmY1YjBkMDQxMTNlNjQ0N2ZiMTQ1ZTZiMGM4NjU5Y2E0MjM3ZGQ)

---
_Source: https://npm.io/package/@visual-framework/vf-location-nearest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
