Webview geolocation

#1

webview geolocation is not working on android version 4.4.2; it shows me that my Apps is using location request under location setting but it does not give output data;but in android 7 everything is working fine;

this is my code;i need your help

import React, { Component } from ‘react’;
import { Button, View, WebView } from ‘react-native’;
import { Constants, Location, Permissions } from ‘expo’;

export default class App extends Component {
//
state = {
inputValue: “”,
switchValue: true,
locationResult: null
};

componentDidMount() {
this._getLocationAsync();
}

_handleTextChange = inputValue => {
this.setState({ inputValue });
};

_handleToggleSwitch = () => this.setState(state => ({
switchValue: !state.switchValue
}));

_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== ‘granted’) {
this.setState({
locationResult: ‘Permission to access location was denied’,
});
}

let location = await Location.getCurrentPositionAsync({});
this.setState({ locationResult: JSON.stringify(location) });
};

///

constructor(props) {
super(props);
this.onPressBroken = this.onPressBroken.bind(this);
this.onPressWorks = this.onPressWorks.bind(this);
this.reload = this.reload.bind(this);
}
onPressBroken() {
this.webview.injectJavaScript(‘x = “test”;’);
console.log(‘injected broken’);
}
onPressWorks() {
this.webview.injectJavaScript(‘x = “test”; void(0);’);
console.log(‘injected works’);
}
reload() {
this.webview.reload();
}
render() {
return (
<View style={{ flex: 1 }}>
<View style={{ height: 20 }} />
<WebView
ref={ref => (this.webview = ref)}
source={{ uri: ‘https://www.myurl.com’ }}
onError={console.error.bind(console, ‘error’)}
bounces={false}
onShouldStartLoadWithRequest={() => true}
javaScriptEnabledAndroid={true}
startInLoadingState={true}
style={{ flex: 1 }}
/>
<Button onPress={this.onPressBroken} title={‘Broken’} />
<Button onPress={this.onPressWorks} title={‘Works’} />
<Button onPress={this.reload} title={‘Reload’} />

);
}
}

thanks

0 Likes

closed #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

0 Likes