Things to watch-out while implementing Live Location Sharing in React Native

Barath Kumar
3 min readNov 2, 2021

Already i posted a blog on how we could share the live location from one app to another using action cables in react native app. If you are not aware of it check out the link below

Now lets see about the things that we have to watch-out for while implementing the above feature.

Table Of Contents

· Start a Foreground Service when needed
· Asking for Correct Permission suited for all android device
· Handling the Denial of Location Permission
· Keep an eye on Performance
· Initial Focus of the map

Start a Foreground Service when needed

  • If there are multiple foreground services being started, then in that case, when programatically if try to close the foreground service then the last started foreground service alone closes and the remaining service will be intact
  • This give rise to the constant sticky notification being available even when there are no service running
  • so before starting a foreground service there needs to be a check for whether the foreground service is already available using ReactNativeForegroundService.is_running()

Asking for Correct Permission suited for all android device

  • The app that is been developed might be used over multiple android versions and each android version has different security patches.
  • Before android 10 there is no need to ask for ACCESS_BACKGROUND_LOCATION permission but its needed for android 10+ devices
  • The proper way to fetch the android permission in all case for location is as follows

Handling the Denial of Location Permission

  • If the location permission is been denied then it has to be handled properly
  • The right thing to show when the location permission denied is, why the app needs the location permission. This type of education can help the user to understand the need for the permission
  • Additional thing that could be done is we can education how to enable the denied permission
  • We can also have an entry point to enable the required permission
  • One of the way we show location permission education is attached for reference.

Keep an eye on Performance

  • While playing with maps and animations inside it we may forget to have a look on performance
  • We need to be careful because having too much of animation on the map could lead to performance issue very easily
  • So have a regular check over the performance while developing

Initial Focus of the map

  • Once the map is been rendered it will by default render a world map, which is not needed at all
  • One thing we can do is hardcode the value of the initialRegion property in react-native-maps
  • The other efficient way of doing is focusing the map towards the markers you have and this can be done using inbuilt fitToCoordinates function
  • The below code will help to focus the map region based on desired coordinates

Conclusion

So the about mentioned Stuffs will be useful, if you are considering to implement the live location sharing feature. Hope the reading would have helped you out.

Thank you for reading the article.

--

--