SHARE
TWEET

Untitled

a guest Jun 27th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import {GooglePlacesAutoComplete} from 'react-native-google-places-autocomplete';
  3.  
  4. export default class Search extends Component {
  5.   render() {
  6.     return(
  7.       <GooglePlacesAutoComplete
  8.         placeholder = "Para onde?"
  9.         placeholderTextColor = "#333"    
  10.         onPress = {() => {}}
  11.         query = {{
  12.           key: "Minha chave da api entra aqui, tirei por enquanto...",
  13.           language: "pt"
  14.         }}
  15.         textInputProps = {{
  16.           autoCapitalize: "none",
  17.           autoCorrect: false
  18.         }}
  19.         fetchDetails
  20.         enablePoweredByContainer = {false}
  21.       />
  22.     );
  23.   }
  24. }
  25.      
  26. import React, { Component } from 'react';
  27. import {View, PermissionsAndroid} from "react-native";
  28. import MapView, { PROVIDER_GOOGLE } from "react-native-maps";
  29. import Search from "../search";
  30.  
  31. export default class Map extends Component {
  32.  
  33.   state = {
  34.     latitude: 0,
  35.     longitude: 0,
  36.     latitudeDelta: 0.005,
  37.     longitudeDelta: 0.005,
  38.   };
  39.  
  40.   async componentWillMount() {
  41.  
  42.     try {
  43.       const granted = await PermissionsAndroid.request(
  44.         PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
  45.         {
  46.           title: 'Permissão necessária!',
  47.           message: 'Para que este app funcione corretamente você precisa conceder permissão de uso do GPS',
  48.           buttonPositive: 'OK',
  49.         }
  50.       );
  51.  
  52.       if (granted === PermissionsAndroid.RESULTS.GRANTED) {
  53.         navigator.geolocation.watchPosition(
  54.           ({coords:{latitude, longitude}}) => {
  55.             this.setState({  
  56.               latitude,
  57.               longitude,
  58.             });
  59.           }, //sucesso
  60.  
  61.           () => {}, //erro
  62.  
  63.           {
  64.             timeout: 2000,
  65.             enableHighAccuracy: true,
  66.             maximumAge: 1000,
  67.           }
  68.         );
  69.       } else {
  70.         console.log("GPS não permitido");
  71.       }
  72.     } catch (erro) {
  73.       console.log(err);
  74.     }
  75.   }
  76.  
  77.   render() {
  78.     const {latitude, longitude, latitudeDelta, longitudeDelta} = this.state;
  79.  
  80.     return (
  81.         <View style = {{flex: 1}}>
  82.           <MapView
  83.               style = {{flex: 1}}
  84.               provider = {PROVIDER_GOOGLE}
  85.               region = {{
  86.                 latitude,
  87.                 longitude,
  88.                 latitudeDelta,
  89.                 longitudeDelta
  90.               }}
  91.               showsUserLocation = {true}
  92.               showsMyLocationButton
  93.           />
  94.           <Search />
  95.         </View>
  96.     );
  97.   }
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top