ユーザ用ツール

サイト用ツール


サイドバー

reactnative:react-native-geolocation-service

react-native-geolocation-service

インストール手順

npm install react-native-geolocation-service

android/app/build.gradleに追加

android/app/build.gradle
dependencies {
    implementation project(':react-native-maps')
    implementation ("com.google.android.gms:play-services-maps:+") {
        force = true;
    }
    implementation 'com.android.support:multidex:1.0.0'
    implementation project(':react-native-background-timer')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-geolocation-service')  // ADD
    compile(project(':react-native-geolocation-service')) {         // ADD
        exclude group: 'com.google.android.gms', module: 'play-services-location' // ADD
    } // ADD
    compile 'com.google.android.gms:play-services-location:16.0.0' // ADD
}

android/setting.gradleに追加

android/setting.gradle
rootProject.name = 'native_background_timer'
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
include ':react-native-background-timer'
project(':react-native-background-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer/android')
 
include ':app'
 
include ':react-native-geolocation-service' //ADD
project(':react-native-geolocation-service').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-geolocation-service/android') //ADD

\android\app\src\main\java\com\native_background_timer\MainApplication.javaに追加

\android\app\src\main\java\com\native_background_timer\MainApplication.java
package com.native_background_timer;
 
import android.app.Application;
 
import com.facebook.react.ReactApplication;
import com.airbnb.android.react.maps.MapsPackage;
import com.ocetnik.timer.BackgroundTimerPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
 
import java.util.Arrays;
import java.util.List;
 
import com.agontuk.RNFusedLocation.RNFusedLocationPackage; // ADD
 
public class MainApplication extends Application implements ReactApplication {
 
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }
 
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new MapsPackage(),
            new BackgroundTimerPackage(),
            new RNFusedLocationPackage()  // ADD
      );
    }

ここの「Looking for JS files inエラー」が発生した

App.jsの修正

App.js
・・・
import Geolocation from 'react-native-geolocation-service'; // ADD
・・・
  async getLocation() {
 
    // navigator.geolocation.getCurrentPosition( // CHANGE
    Geolocation.getCurrentPosition(
      (resolve) => {
        console.log("resolve")
        const location = JSON.stringify(resolve)
        console.log(location)
・・・
reactnative/react-native-geolocation-service.txt · 最終更新: 2019/04/03 04:56 by ips