|
|
@ -1,24 +1,37 @@ |
|
|
|
import React, { useEffect, useState } from "react"; |
|
|
|
import { StyleSheet, View } from "react-native"; |
|
|
|
import React, { useContext } from "react"; |
|
|
|
import { Button, StyleSheet, View, Text } from "react-native"; |
|
|
|
import MapView, { Marker } from "react-native-maps"; |
|
|
|
|
|
|
|
import colors from "../config/colors"; |
|
|
|
import { screen_width, screen_height } from "../config/dimensions"; |
|
|
|
|
|
|
|
import useLocation from "../hooks/useLocation"; |
|
|
|
import useMarkers from "../hooks/selectFromDB"; |
|
|
|
import MapMarker from "../components/MapMarker"; |
|
|
|
import attachFocusToQuery from "../hooks/useFocus"; |
|
|
|
import * as Location from 'expo-location'; |
|
|
|
import { EventLocationContext } from "../context/EventLocationContext"; |
|
|
|
// import SearchBox from "../components/maps/SearchBox";
|
|
|
|
|
|
|
|
function MapFormScreen(props) { |
|
|
|
//Implementação posterior: É interessante adcionar um searchBox para que o usuário busque um endereço (google places autocomplete é uma api paga)
|
|
|
|
var address; |
|
|
|
|
|
|
|
|
|
|
|
const MapFormScreen = (props) => { |
|
|
|
const location = useLocation({ |
|
|
|
latitude: -22.1070263, |
|
|
|
longitude: -51.3948396, |
|
|
|
latitude: -23.533773, |
|
|
|
longitude: -46.625290, |
|
|
|
}); |
|
|
|
const getAddress = async(coordenadas) => { |
|
|
|
Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc"); |
|
|
|
|
|
|
|
const hasToQuery = attachFocusToQuery(); |
|
|
|
const markers = useMarkers(hasToQuery); |
|
|
|
address = await Location.reverseGeocodeAsync(coordenadas.x); |
|
|
|
console.log(address); |
|
|
|
// address[0].street+", " + address[0].name}
|
|
|
|
// {address[0].district}
|
|
|
|
global.eventCoordinates = coordenadas.x; |
|
|
|
context.saveNewLocation(address[0].street+", " + address[0].name); |
|
|
|
} |
|
|
|
|
|
|
|
const context = useContext(EventLocationContext); |
|
|
|
//console.log(context.eventLocation);
|
|
|
|
|
|
|
|
// console.log(markers);
|
|
|
|
const map_scale = 0.003; |
|
|
@ -35,27 +48,30 @@ function MapFormScreen(props) { |
|
|
|
style={styles.mapStyle} |
|
|
|
showsUserLocation={true} |
|
|
|
initialRegion={{ |
|
|
|
latitude: local.latitude, |
|
|
|
longitude: local.longitude, |
|
|
|
latitude: -23.533773, |
|
|
|
longitude: -46.625290, |
|
|
|
...lat_long_delta, |
|
|
|
}} |
|
|
|
region={{ |
|
|
|
latitude: local.latitude, |
|
|
|
longitude: local.longitude, |
|
|
|
latitude: -23.533773, |
|
|
|
longitude: -46.625290, |
|
|
|
...lat_long_delta, |
|
|
|
}} |
|
|
|
> |
|
|
|
<Marker |
|
|
|
draggable={true} |
|
|
|
coordinate={{ |
|
|
|
latitude: local.latitude, |
|
|
|
longitude: local.longitude, |
|
|
|
latitude: -23.533773, |
|
|
|
longitude: -46.625290, |
|
|
|
}} |
|
|
|
onDragEnd={(e) => |
|
|
|
console.log({ x: e.nativeEvent.coordinate }) |
|
|
|
getAddress({ x: e.nativeEvent.coordinate }) |
|
|
|
} |
|
|
|
></Marker> |
|
|
|
</MapView> |
|
|
|
|
|
|
|
<Button title="Confirmar" onPress={() => props.navigation.goBack(null)} /> |
|
|
|
<Text>{context.eventLocation.toString()}</Text> |
|
|
|
</View> |
|
|
|
); |
|
|
|
} |
|
|
|
xxxxxxxxxx