fix: preserve exact coordinates entered in waypoint input fields#392
Merged
DennisOSRM merged 3 commits intogh-pagesfrom Mar 28, 2026
Merged
fix: preserve exact coordinates entered in waypoint input fields#392DennisOSRM merged 3 commits intogh-pagesfrom
DennisOSRM merged 3 commits intogh-pagesfrom
Conversation
When a user types raw GPS coordinates (e.g. '34.129382,-118.141254') into a waypoint field, the previous behaviour sent them to Nominatim as a forward-geocode query, which snapped the result to the nearest named address — sometimes more than a block away from the typed point. Root cause: LRM's autocomplete fires a 'suggest' call as the user types. The suggest results appear in a dropdown and get auto-selected. When Enter is pressed, LRM uses that pre-selected suggest result (with the Nominatim-snapped center) instead of calling geocode. Fix: introduce a coord-preserving geocoder wrapper that detects coordinate strings in both the geocode and suggest paths: - If the input is coordinates, Nominatim reverse-geocodes the point for a human-readable display name, but the result's center is overridden with the exact typed lat/lon. - If the input is a plain address, Nominatim forward-geocode is used as before. - The wrapper bridges the library's Promise-based API to the callback-based API that leaflet-routing-machine expects. Fixes #154 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a coordinate-preserving geocoding path for waypoint input fields so that raw lat/lon inputs keep the exact typed coordinates (while still showing a reverse-geocoded display name), aligning typed-input behavior with the existing ?loc=lat,lon URL path.
Changes:
- Introduced
coordPreserving()geocoder wrapper that detects coordinate strings and reverse-geocodes for display while overriding the resultcenterto the exact input. - Switched the routing plan’s geocoder to
createGeocoder.coordPreserving()and adjusted theleaflet-control-geocoderimport to be side-effect only. - Rebuilt distributable bundles (
bundle.js,bundle.js.map,bundle.raw.js).
Reviewed changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/geocoder.js | Adds coordinate parsing + a wrapper geocoder that preserves exact centers and bridges Promise results to LRM’s callback autocomplete API. |
| src/index.js | Uses the new coordinate-preserving geocoder for waypoint inputs; restores geocoder side-effect import. |
| bundle.js | Rebuilt compiled bundle reflecting the new geocoder behavior. |
| bundle.js.map | Updated sourcemap for rebuilt bundle. |
| bundle.raw.js | Rebuilt raw bundle including updated sources/dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Helper: reverse-geocodes coordinates for display name, but preserves exact latlng. | ||
| function coordResult(latlng, query) { | ||
| return nominatim.reverse(latlng, 67108864).then(function(results) { |
There was a problem hiding this comment.
67108864 is a scale constant corresponding to zoom 18 (256 * 2^18). Adding an inline comment (or deriving it from L.CRS.EPSG3857.scale(18)) would make the intent clearer and avoid this looking like an arbitrary magic number.
Suggested change
| return nominatim.reverse(latlng, 67108864).then(function(results) { | |
| // Use scale corresponding to zoom level 18 (was hard-coded as 256 * 2^18 = 67108864) | |
| return nominatim.reverse(latlng, L.CRS.EPSG3857.scale(18)).then(function(results) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a user types raw GPS coordinates (e.g.
34.129382,-118.141254) into a waypoint input field, Nominatim forward-geocodes the string and snaps the result to the nearest named address — sometimes more than a block away from the entered point.Entering the same coordinates directly in the URL (
?loc=34.129382,-118.141254) works correctly because that path bypasses geocoding.Root Cause
LRM's autocomplete fires a
suggestcall as the user types. The suggest results (from Nominatim forward-geocode) appear in a dropdown and get auto-selected. When Enter is pressed, LRM uses that pre-selected suggest result — with Nominatim's snapped center — instead of the exact coordinates.Fix
Introduces a coordinate-preserving geocoder wrapper (
geocoder.coordPreserving()) that detects coordinate strings in both thegeocodeandsuggestpaths:centeris overridden with the exact typed lat/lon.leaflet-control-geocoder's Promise-based API to the callback-based API thatleaflet-routing-machine's autocomplete expects.Files Changed
src/geocoder.js— AddedcoordPreserving()factory with coordinate detection and Nominatim reverse-geocodesrc/index.js— UsecoordPreserving()geocoder; restoreleaflet-control-geocoderside-effect importbundle.js,bundle.js.map,bundle.raw.js— RebuiltFixes #154