19

I am having a difficult time setting up Leaflet.js with react-native. The documentation tells me to add the following script in my html...

<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>

But I am not sure how I do this using react. Right now my main page is being rendered as follows...

AppRegistry.registerComponent('beacon', () => Home);

And my Home is simply something like...

export default Home = () => {
    return (
        <Provider store={store}>
            <MainMap />
        </Provider>
    );
}

Where/How do I add this script tag to include Leaflet.js? Is it even possible? Is there perhaps another solution?

I haven't seen any examples of react-native and Leaflet.js, if there is one, on github or what not, I'd be happy to see it.

buydadip
  • 8,890
  • 22
  • 79
  • 154

4 Answers4

19

There is a project react-leaflet through which you can use leaflet.js with react.

But currently there is no support for using leaflet.js in react-native. See this issue for more info.

Jickson
  • 5,133
  • 2
  • 27
  • 38
5

Please check this out react-native-maps recommended by react native

Community
  • 1
  • 1
Sareuon
  • 637
  • 1
  • 7
  • 9
5

There is one project I found online that addresses leaflet with React Native: https://github.com/reggie3/react-native-webview-leaflet

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • 2
    Do you know is there any performance penalty for using this instead of `react-native-maps`? I want to use this with `openstreetmap` data. – pouya Jan 25 '20 at 21:36
  • I ended up using react-native-maps, despite this shortcoming, as otherwise I had problems due to the fact that it's a webview and not a native component. – Matthieu Brucher Jan 26 '20 at 09:52
  • 1
    This project is deprecated because no longer maintained. This one is said to be the most recent and up to date : https://github.com/pavel-corsaghin/react-native-leaflet – Brice Joosten Feb 07 '22 at 09:14
0

If you actually want to use leftlet you can host it on website and use react native webview to run in you can sent data between app and web via postMessage function of webview but performance is not good though compare to react native map but atleat you can use bunch of leftlet plugin