You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Implement Search and Geocoder #39
I would like to offer the user the possibility to Search for addresses or Points of Interests and would be cool to also do this with this library!
Might this be something we could add to the library? What would be the best way to do so? Maybe implement as a React hook? I would be willing to put some effort in this if you would give me some guidance on how the preferred implementation could look like.
I could also do a quick implementation in plain Javascript with the MapKit JS framework if this would help?
I prepared two samples for both search and autocomplete attached. Would be super cool to implement something like this in the library! Let me know if this would be something you would want to support!
Thank you for the feature request! Since these APIs are not UI-related, how would you expect mapkit-react to help you to use them?
I think that it should be possible to directly use the MapKit JS APIs without the need for a React-specific wrapper. But there is one rough edge: mapkit-react loads and initializes MapKit JS for you, but currently does not expose the mapkit object. It is currently possible to retrieve it from the global scope and use it when you’re sure that MapKit is already initialized at this point (e.g. map event handlers)1, but this is brittle and does not work if you’re not sure that MapKit is loaded.
Something that we could do would be to provide a useMapkit hook, which would return the same mapkit instance used by mapkit-react (or null if mapkit isn’t loaded yet). We would need to give it the MapKit token, since it is not guaranteed that MapKit has already been initialized at this point. Usage would look like this:
Thank you for the feature request! Since these APIs are not UI-related, how would you expect mapkit-react to help you to use them?
I think that it should be possible to directly use the MapKit JS APIs without the need for a React-specific wrapper. But there is one rough edge: mapkit-react loads and initializes MapKit JS for you, but currently does not expose the mapkit object. It is currently possible to retrieve it from the global scope and use it when you’re sure that MapKit is already initialized at this point (e.g. map event handlers)1, but this is brittle and does not work if you’re not sure that MapKit is loaded.
Something that we could do would be to provide a useMapkit hook, which would return the same mapkit instance used by mapkit-react (or null if mapkit isn’t loaded yet). We would need to give it the MapKit token, since it is not guaranteed that MapKit has already been initialized at this point. Usage would look like this:
thank you so much! I wasn't yet thinking too deep of an exact implementation on this though generally speaking I was thinking of using all the autoloading of the library and calling the MapKit JS APIs via individual hooks (e.g. useMapkitSearch, ...) maybe?
We could even consider some implementation like this:
Thank you for your reply! In my opinion, having a useMapkitSearch hook would be more complex and wouldn’t provide a better experience than simply exposing mapkit and let the user use the same APIs that MapKit JS provides.
Also, it is not clear how the API you proposed handles the case when MapKit hasn’t finished loading yet.
Activity
nikischin commentedon Aug 22, 2023
Samples.zip
I prepared two samples for both search and autocomplete attached. Would be super cool to implement something like this in the library! Let me know if this would be something you would want to support!
Nicolapps commentedon Sep 3, 2023
Thank you for the feature request! Since these APIs are not UI-related, how would you expect mapkit-react to help you to use them?
I think that it should be possible to directly use the MapKit JS APIs without the need for a React-specific wrapper. But there is one rough edge: mapkit-react loads and initializes MapKit JS for you, but currently does not expose the
mapkitobject. It is currently possible to retrieve it from the global scope and use it when you’re sure that MapKit is already initialized at this point (e.g. map event handlers)1, but this is brittle and does not work if you’re not sure that MapKit is loaded.Something that we could do would be to provide a
useMapkithook, which would return the samemapkitinstance used by mapkit-react (ornullif mapkit isn’t loaded yet). We would need to give it the MapKit token, since it is not guaranteed that MapKit has already been initialized at this point. Usage would look like this:What do you think? Would an API like this one help for your use case?
Footnotes
In fact, I’m doing it in one of my own projects: https://github.com/Nicolapps/cmumap/blob/main/src/pages/%5B%5B...slug%5D%5D.tsx#L225 ↩
nikischin commentedon Sep 3, 2023
Hi @Nicolapps,
thank you so much! I wasn't yet thinking too deep of an exact implementation on this though generally speaking I was thinking of using all the autoloading of the library and calling the MapKit JS APIs via individual hooks (e.g.
useMapkitSearch, ...) maybe?We could even consider some implementation like this:
What do you think? (I still think an additional
useMapkithook would be helpful for other implementations)Is this something easy or rather challenging to implement?
Nicolapps commentedon Sep 6, 2023
Thank you for your reply! In my opinion, having a
useMapkitSearchhook would be more complex and wouldn’t provide a better experience than simply exposingmapkitand let the user use the same APIs that MapKit JS provides.Also, it is not clear how the API you proposed handles the case when MapKit hasn’t finished loading yet.