Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

Expo - geofence api not returning values on geofence start

$
0
0

I am attempting to get Expo's geofencing api up and running via a button action in react native.

I've put together an example, but when I attempt to initiate the geofencing action it doesn't do anything. I receive no notification if I am inside or outside a region. Was hoping to get some guidance on this. I can't find a working example. I've already found the following posts that don't seem to work:

Expo startGeofencingAsync not starting

Expo - increase location accuracy with Geofence

App.js

import { StyleSheet, Text, View, Button } from 'react-native';import React, { Component } from 'react';import * as Permissions from 'expo-permissions';import * as Location from 'expo-location';import * as TaskManager from 'expo-task-manager';class App extends Component {state= {  point : {latitude: 0, longitude: 0},  hasLocationPermission: null,  location: null}async componentDidMount() {  this.getLocationsPermissions();  //Permissions.askAsync(Permissions.LOCATION);  //await Location.startLocationUpdatesAsync('firstTask', {  //  accuracy: Location.Accuracy.Balanced,  //});}//update location pointsgetCurrentLoc = async () => {  console.log('retrieving points');  let location = await Location.getCurrentPositionAsync({});  location =  await JSON.stringify(location);  location = await eval( '('+'['+ location +']'+')' );  this.setState({ location: location })}//ask for location permissions getLocationsPermissions = async () => {  let { status } = await Permissions.askAsync(Permissions.LOCATION);  //status && console.log('location: ', status)  if (status !== 'granted') {    this.setState({      errorMessage: 'Permission to access location was denied',    });    } else {      this.setState({ hasLocationPermission : status })    }}_startGeofence = async () => {  console.log('starting geofencing test ...')  Location.startGeofencingAsync('geofence',    [    {      latitude: 40.763882,      longitude: -73.929893,      radius: 50     }     ]    );};  render() {    return (<View><Text>geofence test</Text><Button           onPress={this._startGeofence}          title="AM-I-IN-THE-REGION?"        /><Text>{this.state.location ? `my current location is lat: ${this.state.location[0].coords.latitude}` : `none`}</Text></View>    );  }}export default App;TaskManager.defineTask("geofence", ({ data: { eventType, region }, error }) => {  if (error) {    // check `error.message` for more details.    return;  }  if (eventType === Location.GeofencingEventType.Enter) {    console.log("You've entered region:", region);  } else if (eventType === Location.GeofencingEventType.Exit) {    console.log("You've left region:", region);  }});

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>