I’m making an app about a simple social media where you can share your location while you are in a walk, and I’m using MapView component of react-native-maps. When I use Expo Go, everything is okey, but when I make the build, the apk crashes when I go those components which use a MapView on them. I thought the reason was location permissions, but that’s not true since I did testing with a component that doesn’t use any location of the device, just hardcoding coordinates on the MapView props, but I don’t know the reason yet…
I don’t have any API key of Google Maps, but I don’t know why that could be a problem since in Expo Go using my device everything is okey… I’m stuck.
I’ll give you the sample of code that I used in the component where I publish a new location:
const [location, setLocation] = useState({
latitude: 0,
longitude: 0
})
const getCurrentLocation = async () => {
let { status } = await Location.requestForegroundPermissionsAsync()
if (status !== 'granted') {
alert('Permission denied')
return
}
let location = await Location.getCurrentPositionAsync({})
const currentLocation = {
latitude: location.coords.latitude,
longitude: location.coords.longitude
}
setLocation(currentLocation)
}
const addNewLocation = () => {
const newLocation = {
location: {
latitude: location.latitude,
longitude: location.longitude
},
title: title,
description: description,
author: authData._id,
}
axios.post(`${URL}/addNewPublication`, newLocation)
.then(data => {
console.log(data.data)
})
}
useEffect(() => {
getCurrentLocation()
}, [])
And then, inside the return between other elements:
<MapView
style={{
width: '100%',
height: '40%',
}}
region={{
latitude: location.latitude,
longitude: location.longitude,
latitudeDelta: 0.09,
longitudeDelta: 0.04
}}
scrollEnabled={false}
zoomEnabled={false}
>
<Marker
coordinate={{
latitude: location.latitude,
longitude: location.longitude,
latitudeDelta: 0.09,
longitudeDelta: 0.04
}}
/>
</MapView>
What I expect is the app doesn’t crash when it displays a MapView, and I don’t know the reason why right now, if could be a prop bad defined, not using an API key for Google Maps…
Thank you and sorry for my low english level
JuancaOStos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.