Browse Source

adding condition on reverseGeoCode if it can't return address

master
analuizaff 4 years ago
parent
commit
35f31a81b9
  1. 8
      src/app/screens/MapFormScreen.js

8
src/app/screens/MapFormScreen.js

@ -19,12 +19,18 @@ const MapFormScreen = (props) => {
const location = contextLocation.currentCoordinates; const location = contextLocation.currentCoordinates;
const [marker, setMarker] = useState(context.eventCoordinates); const [marker, setMarker] = useState(context.eventCoordinates);
// console.log(marker);
const getAddress = async (coordenadas) => { const getAddress = async (coordenadas) => {
Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc"); Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc");
const address = await Location.reverseGeocodeAsync(coordenadas); const address = await Location.reverseGeocodeAsync(coordenadas);
context.saveNewLocation(address[0].street + ", " + address[0].name + "\n" + address[0].district, coordenadas);
if (address[0] != undefined) {
context.saveNewLocation(address[0].street + ", " + address[0].name + "\n" + address[0].district, coordenadas);
}
else{//Quando o usuário não da permissão de acesso da localização o geoCode retorna um array vazio
context.saveNewLocation("Erro ao carregar endereço", coordenadas);
}
} }
const setLocation = () => { const setLocation = () => {

Loading…
Cancel
Save