Browse Source

Focuses the map on the user's location in MapForm.

master
GabrielTrettel 3 years ago
parent
commit
06e714f062
  1. 27
      src/app/screens/MapFormScreen.js

27
src/app/screens/MapFormScreen.js

@ -1,4 +1,4 @@
import React, { useContext, useState } from "react";
import React, { useContext, useState, useEffect } from "react";
import { StyleSheet, View, Text, Image } from "react-native"; import { StyleSheet, View, Text, Image } from "react-native";
import colors from "../config/colors"; import colors from "../config/colors";
@ -14,7 +14,16 @@ import OpenStreetMap from "../components/map/OpenStreetMap";
const MapFormScreen = (props) => { const MapFormScreen = (props) => {
const context = useContext(EventLocationContext); //local do evento const context = useContext(EventLocationContext); //local do evento
const contextLocation = useContext(CurrentLocationContext); //local do usuário
const [position, setPosition] = useState(null);
const location = useContext(CurrentLocationContext).currentCoordinates;
useEffect(() => {
setPosition({
lat: location["latitude"],
long: location["longitude"],
zoom: 16.5,
});
}, [location]);
const [moveEndListener, setMoveEndListener] = useState(""); const [moveEndListener, setMoveEndListener] = useState("");
console.log(moveEndListener); console.log(moveEndListener);
@ -39,23 +48,13 @@ const MapFormScreen = (props) => {
props.navigation.goBack(null); props.navigation.goBack(null);
}; };
const map_scale = 0.003;
const lat_long_delta = {
latitudeDelta: map_scale,
longitudeDelta: map_scale * (screen_width / screen_height),
};
const default_location = {
latitude: -12.901799,
longitude: -51.692116,
latitudeDelta: 70,
longitudeDelta: 70 * (screen_width / screen_height),
};
return ( return (
<View style={styles.container}> <View style={styles.container}>
<OpenStreetMap <OpenStreetMap
style={styles.mapStyle} style={styles.mapStyle}
animateToPosition={position}
moveEndListener={setMoveEndListener} moveEndListener={setMoveEndListener}
/> />
<View style={styles.markerFixed}> <View style={styles.markerFixed}>
<Image <Image

Loading…
Cancel
Save