MapView and Current Location

#1

I’m a little confused about how to display current location in a MapView. The MapView API has the showsUserLocation prop, which says the following:

" NOTE : You need to add NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation, otherwise it is going to fail silently ! You will also need to add an explanation for why you need the users location against NSLocationWhenInUseUsageDescription in Info.plist. Otherwise Apple may reject your app submission."

Additionally, there’s the expo Location API, which allows me to get the current location via getCurrentPositionAsync. I’m not quite sure how these play together So here are my questions:

  1. How do I update the Info.plist in Expo? I’d prefer not to eject so I’m wondering if there’s a way to do this simply.

  2. Assuming I can use showsUserLocation, what happens if I publish this? Will it break? Silently fail?

  3. Assuming I can’t use showsUserLocation and I instead need to roll my own location marker using the Location API, will I still have issues with Apple possibly rejecting the app?

#2

Hey @ppetrick,

You’ll have to add it in your app.json under the ios.infoPlist property: https://docs.expo.io/versions/v32.0.0/workflow/configuration#ios

Once you’ve done so, you’ll have to create a new build in order for the changes to take effect. Publishing alone will not be enough.

Cheers,

Adam

#3

Great, thanks! I assume that applies to Testflight as well?

Also, what is the user Permissions experience in this case? Does MapView ask the user for permission to see their location and if so, when? If not, do I need to request the location permission? Or does it just automatically allow using the location after approval? Sorry for all the questions, but the docs are relatively silent on this stuff and I don’t have any prior experience using location.

#4

Yeah, it will apply to TestFlight as well!

I believe if you have the showsUserLocation set to true it will prompt for permissions, but I can’t say for sure. It’d shouldn’t be hard to give it a quick test and see if it does. Unfortunately we just use a wrapper around the react-native-maps library so we don’t have full dominion over this. You’ll likely want to request location permission before rendering the map and handle the case where the user does not grant permissions so you can handle it more elegantly in a proactive manner than a reactive one.

1 Like
closed #6

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.