title: React-native Android geolocation
body: <p>I need to detect user's geolocation on React-native Android but the current implementation supports only iOS. I haven't found any tutorials or related questions anywhere. </p>
  
  <p>I have tried to create my own Android native component for this. I have tried it with the emulator (setting some coordinates via commandline) and with a phone but there is no gps icon in the action bar and the react callback has no data in it.</p>
  
  <p>I'm trying to get the last known location immediately and I'm also setting up an event listener for updates.</p>
  
  <pre><code>public class GeoLocation extends ReactContextBaseJavaModule implements
      GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
  
  protected static final String TAG = "GeoLocation";
  protected GoogleApiClient mGoogleApiClient;
  protected Location mLastLocation;
  
  
  public GeoLocation(ReactApplicationContext reactContext) {
      super(reactContext);
      buildGoogleApiClient();
  }
  
  @Override
  public String getName() {
      return "GeoLocation";
  }
  
  protected synchronized void buildGoogleApiClient() {
      mGoogleApiClient = new GoogleApiClient.Builder(getReactApplicationContext())
              .addConnectionCallbacks(this)
              .addOnConnectionFailedListener(this)
              .addApi(LocationServices.API)
              .build();
      mGoogleApiClient.connect();
  }
  
  @Override
  public void onConnected(Bundle connectionHint) {
  
      mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
      //WritableMap params = Arguments.createMap();
  
      //Can I use ConcurrentHashMap instead of WritableMap?
      ConcurrentHashMap&lt;String, String&gt; params = new ConcurrentHashMap();
      params.put("lastLocation", mLastLocation.toString());
      sendEvent(getReactApplicationContext(), "geoCoordsChanged", params);
  }
  
  @Override
  public void onConnectionFailed(ConnectionResult result) {
      Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode());
  }
  
  @Override
  public void onConnectionSuspended(int cause) {
      mGoogleApiClient.connect();
  }
  
  @ReactMethod
  public void getLastLocation(Callback success,Callback err){
      try {
          String msg = "No location found yet";
  
          if(mLastLocation != null){
              msg = mLastLocation.toString();
          }
  
          success.invoke(msg);
      } catch (Exception e) {
          err.invoke(e.getMessage());
      }
  }
  
  private void sendEvent(ReactContext reactContext,
                         String eventName,
                         @Nullable ConcurrentHashMap&lt;String, String&gt; params) {
    try {
        reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
    } catch(Exception e){
  
    }
  }
  </code></pre>
  
  <p>Permissions: </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.SEND_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  
  &lt;application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher"
    android:theme="@style/AppTheme"&gt;
  
      &lt;meta-data android:name="com.google.android.gms.version"
                 android:value="@integer/google_play_services_version" /&gt;
  </code></pre>
  
  <p>I haven't found anything relevant from the logcat logs either. Any tips what is wrong with this code or any kind of solution for getting geocoordinates would be great!</p>