Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

React Native Module to use Android Geolocation via Google Play API

NotificationsYou must be signed in to change notification settings

garysye/react-native-android-geolocation

Repository files navigation

React Native Module to use Android Geolocation via Google Play API

Installation

npm install --save react-native-android-geolocation

Add it to your React Native android project

  • Inandroid/setting.gradle
...include':RNAndroidGeolocation',':app'project(':RNAndroidGeolocation').projectDir=newFile(rootProject.projectDir,'../node_modules/react-native-android-geolocation')
  • Inandroid/app/build.gradle
...dependencies {...    compile project(':RNAndroidGeolocation')}
  • InMainActivity.java
importcom.rnandroidgeolocation.AndroidGeolocationPackage;// <--- Add import herepublicclassMainActivityextendsActivityimplementsDefaultHardwareBackBtnHandler {privateReactInstanceManagermReactInstanceManager;privateReactRootViewmReactRootView;@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);mReactRootView =newReactRootView(this);mReactInstanceManager =ReactInstanceManager.builder()                .setApplication(getApplication())                .setBundleAssetName("index.android.bundle")                .setJSMainModuleName("index.android")                .addPackage(newMainReactPackage())                .addPackage(newAndroidGeolocationPackage())// <--- Add package command here                .setUseDeveloperSupport(BuildConfig.DEBUG)                .setInitialLifecycleState(LifecycleState.RESUMED)                .build();mReactRootView.startReactApplication(mReactInstanceManager,"ChewApp",null);setContentView(mReactRootView);    }  ......}

Google Play API Installation

In case you haven't done it already, you will also need to install the corresponding Google Play SDK. To do this run

$cd /path/to/your/android-sdk/tools$ android sdk

and select the Google Play SDK extras as pictured below:

Google Play SDK Installation

Example

varAndroidGeolocation=require('react-native-android-geolocation');AndroidGeolocation.getCurrentLocation((position)=>this.setState({position:position}),(error)=>this.setState({error:error}));

License

ISC

About

React Native Module to use Android Geolocation via Google Play API

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp