Location request for Android emulator using React-Native

I am creating my first reaction app for Android. What I want to do is display the current location . But it does not work on my emulator . Instead, a Location Identification error message appears in the console. Here is a sample code from idex.android.js file:

initGeoloc() { navigator.geolocation.getCurrentPosition( (position) => { console.log(JSON.stringify(position)); } ); } render() { this.initGeoloc(); ... some more code and the view 

The code is very simple, so I don't think the error comes from here. I added this permission to my AndroidManifest.xml file (ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION):

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <application android:allowBackup="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> <uses-library android:name="com.google.android.maps" /> <meta-data android:name="com.google.android.geo.API_KEY" android:value="mykey"/> </application> 

I don’t see anything bad either, so I think the problem comes from the Android emulator. I am using Android Virtual Device Manager to create a virtual appliance API level 23 Nexus 5, Google API (Google Inc.). Geolocation is activated on the device, but I have not seen any geolocation tools in the development or configuration tools. Therefore, probably the error comes from here. The virtual device does not return any location.

How can i fix this?

+8
android android-emulator react-native geolocation
source share
2 answers

This question has been answered in this thread. How to emulate GPS location in Android emulator? Sorry for the duplicate. I fixed my problem with telnet.

+2
source share

set enableHighAccuracy false, the problem will be resolved.

 navigator.geolocation.getCurrentPosition((position) => { console.log(position); }, error => console.error(error), { enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 }); 
+6
source share

All Articles