I am trying to access navigator.geolocation in my application.
I have also set "NSLocationWhenInUseUsageDescription" in my info.plist.
But, when I run my app, It throws an error saying "undefined is not an object (evaluating navigator.geolocation.getCurrentPosition)" .
Here is my code -
import React, { Component } from 'react';
import {
AppRegistry,
Image,
ListView,
StyleSheet,
Text,
Navigator,
TouchableHighlight,
Alert,
TouchableOpacity,
View
} from 'react-native';
import Spinner from 'react-native-loading-spinner-overlay'
var GiftedSpinner = require('react-native-gifted-spinner');
var GLOBAL = require('./Globals');
var stateName;
var latitude;
var longitude;
class PersonByLocationPage extends Component {
constructor(props) {
super(props);
this.data = this.props.data;
navigator.geolocation.getCurrentPosition(
(position) => {
var crd = position.coords;
latitude = crd.latitude;
longitude = crd.longitude;
// alert(latitude);
// alert(longitude);
},
(error) => alert(error.message),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
this.REQUEST_URL = 'sample';
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
loaded: false,
networkError: false,
};
}
Can anybody tell what I am doing wrong ?