Open google Navigation directly in React Native. (android)
Recently I have been working on a project that involves orders and delivery of a certain product. The Requirement is that we have this driver app and drivers, drivers deliver the stuff. So when he received an order, we have to redirect the driver to the google navigation so that he can navigate easily.
There were plenty of plugins over the internet that can help me achieve that, but I am going to share the one that is so simple and minimalistic and easy to use. I worked with a plugin called react-native-send-intent
- You can download it in your project with
yarn add react-native-send-intent
here is the link to the library
Well I have to open the app and what this plugin does is it have a bunch of pre-build helper native functions, the one we can use was openMaps and openMapsWithRoute
openMaps
This will help you with opening the google app with a latitude and longitude, and it receives just query, you can learn about the query from the official page
SendIntentAndroid.openMaps("Piccadilly Circus Station, London, United Kingdom");
OR
SendIntentAndroid.openMaps("40.730610, -73.935242");
openMapsWithRoute
This helper function will help you open the navigation directly instead of opening the app; therefore, you start your journey as fast as you execute the function.
It Receives two-parameter, one is the Query, and the other one is the mode.
you can learn about Query and mode from the official page
SendIntentAndroid.openMapsWithRoute('40.730610, -73.935242', 'd'),
OR
SendIntentAndroid.openMapsWithRoute('Piccadilly Circus Station, London, United Kingdom', 'd'),
How to open your app again after reaching the destination?
Well, you can start up a foreground service (Simple Foreground Service), and try to get the location in the headless task, and set up a geofence, so when the destination distance from the locations falls into the minimum given, it should Start your app back with.
SendIntentAndroid.SendIntentAndroid.openApp("com.Your.app.BundlerName").then(wasOpened => {});