Reputation: 3
I'm using geolocation but i get the error: "undefined is not an object(evaluating 'navigator.geolocation.getCurrentPosition') According to documentation, it's not necessary import Geolocation using react native 0.60 version or above.
version: react-native-cli: 2.0.1 react-native: 0.60.4
import React, { Component } from "react";
import {
StyleSheet,
Text,
View,
Alert,
TouchableOpacity
} from "react-native";
export default class App extends Component {
state = {
location: null
};
findCoordinates = () => {
navigator.geolocation.getCurrentPosition(
position => {
const location = JSON.stringify(position);
this.setState({ location });
},
error => Alert.alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this.findCoordinates}>
<Text style={styles.text}>Find My Coords?</Text>
<Text>Location: {this.state.location}</Text>
</TouchableOpacity>
</View>
);
}
}
Upvotes: 0
Views: 325
Reputation: 416
i faced the same problem and i think that from 0.60 and above navigator
it isn't supported so you have to use Geolocation
Upvotes: 1