Repository navigation
v3.0.0
A rewrite around one use case: capturing one precise point in a form. The default map is now OpenStreetMap through Leaflet, with no API key; Google Maps and MapLibre are opt-in providers. The upgrade guide with every v1 and v2 API is docs/migration.md.
The MIT License applies to this release and to all prior versions of location-picker.
Added
<location-picker>, a form-associated custom element: it submits throughFormData(name,lat-name,lng-name,address-name), validates withrequired, resets with the form and restores on back/forward navigation (#4).import 'location-picker'and the script build define it;location-picker/corestays side-effect free.- Keyless default: Leaflet 1.9.4 (loaded on demand from jsDelivr with Subresource Integrity, only when
window.Lis absent) and OpenStreetMap tiles, with the attribution always visible. - Providers as adapters:
leafletProvider(),googleProvider()(importLibrary, a CSS-overlay pin, optionalAdvancedMarkerElement) andmaplibreProvider()(bring your ownmaplibre-gl, OpenFreeMap style by default). Custom engines plug in through the publicProviderAdaptercontract. - Address search (
search, #10) and reverse geocoding (reverse-geocode,addresschange), paired with the provider: Photon for Leaflet and MapLibre,PlaceAutocompleteElementand the Google Geocoder for Google. Custom geocoders are supported. - Field mode for phones (
presentation="field", or"auto"for coarse-pointer viewports up to 640 px wide): a compact form control with the address or coordinates and a "Choose on map" button opens the map in a full-screen modal<dialog>sheet. Pans, search picks and locates there are a draft until Confirm (input+changewith their source); Cancel, Escape (and the system back gesture where the browser sends it to dialogs) andclose()leave the value untouched. The engine loads on first open. New:showPicker(),close(), thetoggleevent, thefield,field-value,field-button,sheet,sheet-headerandcancel-buttonparts,:state(open), and thechooseOnMap,fieldPlaceholderandcancelmessages. - A locate button (
locate="button", #1) that prompts only on click;locate()with a timeout and a watchdog, so it never hangs. - Bound inputs (
lat-input,lng-input,value-input,address-input) that receive nativeinput/changeevents, for jQuery, Livewire, Alpine and server-rendered forms with progressive enhancement. inputandchangeevents withdetail.source(user,api,geolocation,search);readyanderrorevents;onInput,onChange,onAddressChange,onReadyandonErrorclass callbacks.LocationPickerErrorwith stablecode, one-linefixandlevel; messages read[location-picker] … Fix: ….location-picker/utils:parseLatLng(decimal, DMS,geo:URIs, Google, OpenStreetMap and Apple Maps URLs),formatLatLng,normalizeLatLng,isLatLng.- Script build
dist/location-picker.global.js(theunpkgandjsdelivrfields;https://cdn.jsdelivr.net/npm/location-picker@3), which setswindow.LocationPickerand defines the element. - Theming through CSS custom properties,
::part(), slots and:state();marker="none"hides the pin (#9); dark mode and right-to-left layouts; keyboard support and a polite live region. - Experimental, opt-in WebMCP tools (
webmcpattribute,registerWebMcpTools()). - JSX typings for React 19, Preact, Solid, Vue and Svelte (
location-picker/jsx/*),custom-elements.json,llms.txt, an Agent Skill (skills/location-picker/SKILL.md, shipped in the package) andAGENTS.md. centersets where the map starts while no value is chosen, instead of a built-in default location (#7).- On the website: a no-code snippet generator for WordPress, Webflow, Squarespace, Shopify and form services (
/embed/, with the guide docs/embed.md), and a hosted pick link (/pick/) that asks a person for a location with nothing to install and returns it by copy, redirect orpostMessage.
Known issues
- Writing
valuewhile the user is moving the map (for example from aninputlistener that writes the live value back) stops the move without a commit. Update framework state fromchange; Vue'sv-modelis not affected. - The class option
webmcp: truedoes not register WebMCP tools yet; callregisterWebMcpTools(picker). The element'swebmcpattribute works. Planned for 3.1. - Field mode (
presentation="field"): a value set while the sheet is closed, and an address that resolves after Confirm, update the field's text but are not announced to screen readers. The sheet itself and the field's label and value are accessible.
Breaking
.map(syncgoogle.maps.Map, v1/v2) is nowundefineduntilready. It is still set synchronously withprovider: googleProvider()on a page where Google Maps is already loaded with a classic script tag (a one-line fix).- Implicit Google provider (v2): Google is selected only by
apiKey,mapId,useAdvancedMarkeror a 3rd constructor argument (or an explicitprovider: 'google'). Otherwise the picker uses OpenStreetMap and logs a hint whengoogle.mapsis loaded.
Default changed
- Option
setCurrentPosition(default true):truenow maps tolocate: 'auto', and the default islocate: 'off'. Nothing prompts for location on load unless you ask for it.
Changed
onLocationChange(pos)is called likeonChange(de-duplicated; the detail is a superset ofLatLng). Like v2's firstidle, it is also called once afterreadywith the current value (sourceapi), but only when a value is set: an unset picker has no position to report..centerMarker/ PNG pin: the pin is an SVG themed with CSS custom properties. Class mode keeps.lp-pin.centerMarker(the alias class), and the element exposes::part(pin)."type": "module",engines.node >= 18: the package is now"type": "commonjs"with.mjs/.cjsfiles and has noenginesfield. The deep.mjs/.cjspaths are kept.setLocation(lat, lng)now commits: it firesinputthenchangewith sourceapi. It also accepts anyLatLngInput('48.8584, 2.2945',{ lat, lng }). An out-of-range latitude is clamped with a warning.setCurrentPosition()is an alias oflocate()that keeps the current zoom. It resolves with aLocationDetailand rejects with aLocationPickerErrorthat has a.code.
Removed
- The Tripoli fallback. With no value and no
center, the map shows a world view (20, 0) at zoom 2 and the picker stays unset (#7). The frozen v1 file keeps the old behaviour.
Fixed
getMarkerPosition()returns a normalised position (longitude wrapped into [-180, 180), latitude clamped; #12) and never a fake{ 0, 0 }. While the picker is unset it returns the view centre and warns once.destroy()removes the created map, every listener and every node.- Type declarations:
@types/google.mapsis an optional peer referenced only bylocation-picker/google, specifiers carry explicit extensions, and no declaration file imports CSS (#2). 0is a valid latitude and longitude everywhere (#11).