Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import React, { useEffect, useState } from 'react';
  2. import { View } from 'react-native';
  3. import MapView from 'react-native-maps';
  4. import Geolocation from '@react-native-community/geolocation';
  5. import Search from '../search';
  6.  
  7. export function Map(props: Props) {
  8. const [region, setRegion] = useState(null)
  9.  
  10. useEffect(() => {
  11. Geolocation.getCurrentPosition(
  12. ({ coords: { latitude, longitude } }) => {
  13. setRegion({
  14. region: {
  15. latitude,
  16. longitude,
  17. latitudeDelta: 0.0143,
  18. longitudeDelta: 0.0134
  19. }
  20. })
  21. },//sucesso
  22. () => { }, //erro
  23. {
  24. timeout: 2000,//espera encontrar a localizacao em ate 2 segundos se nao cai em erro
  25. enableHighAccuracy: true,//Para pegar a localizacao via gps
  26. maximumAge: 1000, //especie de cache que salva a localizacao
  27. }
  28. );
  29. }, [])
  30.  
  31. return (
  32. <View style={{ flex: 1 }}>
  33. <MapView
  34. style={{ flex: 1 }}
  35. region={region}
  36. showsUserLocation //Poem um icone onde usuario esta
  37. loadingEnabled //Poem um active mostrando que esta carrregando
  38. />
  39. <Search></Search>
  40. </View>
  41. );
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement