Reputation: 41
How can I make sure that user will not use the mock location and fake gps while using react native maps?
When the developer mode is enabled on the device, users can still use the mock location do we have way to stop it?
<MapView
provider={PROVIDER_GOOGLE}
ref={ map => { this.map = map }}
region={this.state.mapRegion}
//onRegionChangeComplete={region => this.setState({ region })}
style={{height: this.state.height}}
showsUserLocation = {false}
followUserLocation = {true}
showsMyLocationButton={false}
onMapReady={this.onMapReady}
zoomEnabled = {true}>
{this.state.geoFenceCoords!=undefined && this.state.geoFenceCoords.map((coords,i) => (
<MapView.Polygon
key={i}
coordinates={coords}
strokeColor="rgb(84,181,64)"
strokeWidth={2}
fillColor="rgba(84,181,64,0.2)"
onPress={() => this.onPress()}
/>
)
)}
{this.state.lastLat!=null && this.state.lastLong!=null && <MapView.Marker
coordinate={{
latitude: this.state.lastLat,
longitude: this.state.lastLong,}}
>
<View style={{justifyContent:'center', alignItems:'center',}}>
<View style={styles.calloutViewPin}>
{this.state.lastLat!= null && this.state.lastLong!=null && <Text style={styles.textLocPin}>Your current location
</Text>}
</View>
<Image source={marker} style={{width: 20, height: 30, paddingTop: 0, marginTop:0}}/>
</View>
</MapView.Marker>}
</MapView>
Upvotes: 1
Views: 5257
Reputation: 6374
u can use this package to check that is location is mocked or not.
react-native-geolocation-service
useEffect(() => {
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
// See error code charts below.
console.log(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
},[])
the position has a check where the location has mocked or not this is the response
{"coords": {"accuracy": 1, "altitude": 0, "altitudeAccuracy": 0, "heading": 318.5695495605469, "latitude": 33.53424587841997, "longitude": 73.13021050283609, "speed": 5.55555534362793}, "mocked": true, "provider": "fused", "timestamp": 1674113136450}
as I have mocked may location then it has mocked:true
Upvotes: 0
Reputation: 1341
You can solve that problem using Mock Location Detecter. This means if the user enables the fake GPS they used the Fake location.
See This:
Upvotes: 1