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?
android android-emulator react-native geolocation
manu
source share