mapbox-gl-geocoder icon indicating copy to clipboard operation
mapbox-gl-geocoder copied to clipboard

forward geocode a lat/long input

Open ArstanWhitebeard opened this issue 8 years ago • 5 comments

In Google Maps you can type either a lat/long or a geocoder search into the search box and it will fly there. mapbox-gl-geocoder cannot handle the former, which is both surprising to the user and a limit to its usefulness.

Ideally if you entered a lat/long input it would recognise it (regex?) and simply fly straight there without needing to call to the geocoder api.

ArstanWhitebeard avatar Jun 02 '17 09:06 ArstanWhitebeard

when one number is >90 or <90 it's obvious which order the coordinates are in, but if both are within -90 to 90 how would you work out if it's lat,lon or lon,lat?

I wonder if it's better to address this upstream in the geocoding api so requests for decimal degree coordinates, dms coordinates work in the api?

andrewharvey avatar Jun 02 '17 23:06 andrewharvey

Currently if you pass in a lng,lat it will reverse geocode since this is how the Mapbox Geocoding API works https://www.mapbox.com/api-documentation/#request-format. Though with some combinations of limit and types it can actually return an error.

Putting aside the question of if this should be handled in the upstream API, I've sketched out how this could work in mapbox-gl-geocoder at https://github.com/andrewharvey/mapbox-gl-geocoder/tree/local-geocoder.

The idea is to allow the app developer to supplier their own local geocoder function to supplement results from the external api. In the sketch I've put together a local coordinate pair example, though the beauty is it's flexible so could also be used in other applications where you may have a local GeoJSON source which you want to include in the geocoder results.

This code is just a sketch, before getting it into something which could be merged, I'd like feedback on what others feel about this?

/cc @tristen

andrewharvey avatar Jul 06 '17 01:07 andrewharvey

https://github.com/mapbox/mapbox-gl-geocoder/blob/master/example/index.js now contains an example of how to do this. I'm thinking it's probably best to leave this up to the implementor (since now with the localGeocoder option it's very easy) rather than including it in core, though I'm not 100% committed to that view.

andrewharvey avatar Dec 23 '17 05:12 andrewharvey

The example of how you can implement this in your own implementation is at https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder-accept-coordinates/. This ticket can be used to track doing this out of the box.

andrewharvey avatar Jan 22 '18 10:01 andrewharvey

#175 included a change to detect lat/lon inputs and provide suggestions from the reverse geocoder. This doesn't include the exact lat/lon so if you want users to be able to forward geocode a lat/lon you'll still need to do something like https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder-accept-coordinates/

I think this ticket should remain open as the forward geocoding lat/lon case is still not supported out of the box.

andrewharvey avatar Jan 21 '19 05:01 andrewharvey