timfpark / react-native-location Goto Github PK
View Code? Open in Web Editor NEWReact Native plug-in that provides GPS location information
License: MIT License
React Native plug-in that provides GPS location information
License: MIT License
I'm unable to build this in it's current state, with RN 0.14.0
. I get:
bundle: Created ReactPackager
uncaught error Error: UnableToResolveError: Unable to resolve module NativeModules from {MY_PROJECT_PATH}/node_modules/react-native-location/RNLocation.ios.js: Invalid directory /Users/node_modules/NativeModules
When changing this line:
var NativeRNLocation = require('NativeModules').RNLocation;
to this:
var NativeRNLocation = require('react-native').NativeModules.RNLocation;
Things start working again. It seems vaguely related to this.
Hi guys
First of all, thanks for this amazing library! It really helped us tackle a number of difficult problems.
One thing, however, that I don't seem to get working is, subscribeToPermissionUpdates
on Android. It seems as though it is never being called.
Beyond that, the library works great on Android and I am pretty sure I installed it correctly.
I am using:
react-native 0.59.5
react-native-location: 2.2.0
While updating my app to latest React Native 0.13.1
I run into following error:
Error building DepdendencyGraph:
Error: Naming collision detected: {project-folder}/node_modules/react-native/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderTouchHistoryStore.js collides with {project-folder}/node_modules/react-native-location/node_modules/react-native/node_modules/react-tools/src/renderers/shared/event/eventPlugins/ResponderTouchHistoryStore.js
at HasteMap._updateHasteMap ({project-folder}/node_modules/react-native/packager/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js:123:13)
at {project-folder}/node_modules/react-native/packager/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js:95:28
at tryCallOne ({project-folder}/node_modules/react-native/node_modules/promise/lib/core.js:37:12)
at {project-folder}/node_modules/react-native/node_modules/promise/lib/core.js:103:15
at flush ({project-folder}/node_modules/react-native/node_modules/promise/node_modules/asap/raw.js:50:29)
at doNTCallback0 (node.js:407:9)
at process._tickCallback (node.js:336:13)
Removing react-native
folder in /node_modules/react-native-location/node_modules/
does fix this error.
Or could you update the dependency to react-native-location
to latest RN ^0.13.1
, please?
[EDIT]
Using peerDependencies might be helpful, too:
// package.json
"peerDependencies": {
"react-native": ">=0.12"
}
[/EDIT]
import RNLocation from 'react-native-location';
RNLocation.configure({
distanceFilter: 5.0
})
RNLocation.requestPermission({
ios: "whenInUse",
android: {
detail: "coarse"
}
}).then(granted => {
if (granted) {
this.locationSubscription = RNLocation.subscribeToLocationUpdates(locations => {
console.log('locations',locations);
/* Example location returned
{
speed: -1,
longitude: -0.1337,
latitude: 51.50998,
accuracy: 5,
heading: -1,
altitude: 0,
altitudeAccuracy: -1
floor: 0
timestamp: 1446007304457.029
}
*/
})
}
})
The command line "console.log('locations',locations);", called just once when init it.
When i tried to change location i do not get the new location.
Ios - working perfectly
Tested on latest version.
Using the latest react native, the react native location does not appear to get installed on NativeExtensions.
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.app.Activity.getMainLooper()' on a null object reference
at com.google.android.gms.common.api.GoogleApi.(Unknown Source:50)
at com.google.android.gms.location.FusedLocationProviderClient.(Unknown Source:8)
at com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Unknown Source:2)
at com.github.reactnativecommunity.location.RNPlayServicesLocationProvider.(RNPlayServicesLocationProvider.java:49)
at com.github.reactnativecommunity.location.RNLocationModule.createPlayServicesLocationProvider(RNLocationModule.java:103)
at com.github.reactnativecommunity.location.RNLocationModule.createDefaultLocationProvider(RNLocationModule.java:96)
at com.github.reactnativecommunity.location.RNLocationModule.configure(RNLocationModule.java:39)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:764)
And then the app is closed
Hello,
is there any implementation with Android and Ios support? Are anyone working on this or the implementation still propesed?
Thanks!
NOT an issue, just an example for using RxJS
to handle locationUpdated
: https://gist.github.com/sectore/a8147ce68fc3966ce142
I'm getting error TypeError: this.nativeInterface.startMonitoringSignificantLocationChanges is not a function
Version:
react-native: 0.57.1
react-native-location: ^2.1.1
Stack trace:
TypeError: TypeError: this.nativeInterface.startMonitoringSignificantLocationChanges is not a function. (In 'this.nativeInterface.startMonitoringSignificantLocationChanges()', 'this.nativeInterface.startMonitoringSignificantLocationChanges' is undefined)
This error is located at:
in HomeScreen (created by SceneView)
in SceneView (at StackViewLayout.js:784)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AnimatedComponent (at StackViewCard.js:69)
in RCTView (at View.js:44)
in AnimatedComponent (at screens.native.js:59)
in Screen (at StackViewCard.js:57)
in Card (at createPointerEventsContainer.js:27)
in Container (at StackViewLayout.js:860)
in RCTView (at View.js:44)
in ScreenContainer (at StackViewLayout.js:311)
in RCTView (at View.js:44)
in AnimatedComponent (at StackViewLayout.js:307)
in Handler (at StackViewLayout.js:300)
in StackViewLayout (at withOrientation.js:30)
in withOrientation (at StackView.js:79)
in RCTView (at View.js:44)
in Transitioner (at StackView.js:22)
in StackView (created by Navigator)
in Navigator (at createKeyboardAwareNavigator.js:12)
in KeyboardAwareNavigator (created by SceneView)
in SceneView (at createTabNavigator.js:39)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in ResourceSavingScene (at createBottomTabNavigator.js:113)
in RCTView (at View.js:44)
in ScreenContainer (at createBottomTabNavigator.js:103)
in RCTView (at View.js:44)
in TabNavigationView (at createTabNavigator.js:197)
in NavigationView (created by Navigator)
in Navigator (created by SceneView)
in SceneView (created by SwitchView)
in SwitchView (created by Navigator)
in Navigator (at createAppContainer.js:388)
in NavigationContainer (at renderApplication.js:34)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AppContainer (at renderApplication.js:33)
This error is located at:
in NavigationContainer (at renderApplication.js:34)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AppContainer (at renderApplication.js:33)
subscribeToSignificantLocationUpdates
subscriptions.js:44:8
componentDidMount
index.js:45:6
wrapper
native.js:486:32
fn
native.js:507:23
commitLifeCycles
ReactNativeRenderer-dev.js:12144:10
commitAllLifeCycles
ReactNativeRenderer-dev.js:13496:8
invokeGuardedCallbackImpl
ReactNativeRenderer-dev.js:92:15
invokeGuardedCallback
ReactNativeRenderer-dev.js:306:36
commitRoot
ReactNativeRenderer-dev.js:13702:8
completeRoot
ReactNativeRenderer-dev.js:15269:13
performWorkOnRoot
ReactNativeRenderer-dev.js:15197:21
performWork
ReactNativeRenderer-dev.js:15090:24
performSyncWork
ReactNativeRenderer-dev.js:15047:14
requestWork
ReactNativeRenderer-dev.js:14925:19
scheduleWork
ReactNativeRenderer-dev.js:14711:16
scheduleRootUpdate
ReactNativeRenderer-dev.js:15429:15
render
ReactNativeRenderer-dev.js:16142:20
renderApplication
renderApplication.js:59:34
run
AppRegistry.js:101:10
runApplication
AppRegistry.js:195:26
__callFunction
MessageQueue.js:349:47
<unknown>
MessageQueue.js:106:26
__guard
MessageQueue.js:297:10
callFunctionReturnFlushedQueue
MessageQueue.js:105:17
Hi, do you have an APK file? I'd like to test the example. Thanks!
Is there any method to recognize the status of the unsubscribed?
Thanks for this library, it works good with android but with iOS it gives Native Module cannot be null error.
Things I did:
can someone help?
cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
^
symbol: variable O
location: class VERSION_CODES
I guess the build tools version is old
Hi !
I'm intressted to know the benefits of this library compared to https://facebook.github.io/react-native/docs/geolocation.html
We are currently using that in our app, but its very slow on android compared to IOS.
Tnx :)
On Android, subscribeToLocationUpdates()
returns a set of locations the first time it's called, but after that, it sends a new locations
array extremely infrequently - on the order of once every 10 minutes (even if moving significantly). Fine location access is authorized.
On iOS, the method works as expected (using the same code below).
Relevant code is below. Are there any other settings I can adjust?
RNLocation.configure({
distanceFilter: null, // have tried 0, 1, 10, 100
desiredAccuracy: {
ios: 'best',
android: 'highAccuracy'
}
});
unsubscribe = RNLocation.subscribeToLocationUpdates((locations) => {
Alert.alert('locations', JSON.stringify(locations));
});
I am developing a location based app, the app needs to get device location even app running in the background or killed. Can this library do that?
This repo can't working on react native 0.4x currently.
I do the npm install --save react-native-location ,and react-native link
this is my code , it alert me that undefined is not an object
import React,{Component} from 'react';
import {
View,
Text,
StyleSheet,
DeviceEventEmitter,
Dimensions,
} from 'react-native';
import { RNLocation as Location } from 'NativeModules';
Location.requestAlwaysAuthorization();
Location.startUpdatingLocation();
Location.setDistanceFilter(5.0);
export default class RNLocationTest extends Component {
componentWillMount() {
Location.requestAlwaysAuthorization();
Location.startUpdatingLocation();
Location.setDistanceFilter(5.0);
DeviceEventEmitter.addListener('locationUpdated', (location) => {
console.log('^^^^^^^^^^',location);
})
}
render (){
return (
<View style={styles.container}>
<Text>Test location</Text>
</View>
);
}
}
Trying to solve an issue I am having with this otherwise great library! On Android I am getting the following warning:
Possible Unhandled Promise Rejection (id: 0)
Error: Error configuring react-native-location
This occurs on my Android device after I have agreed to all permissions, but turn off my location services / GPS. I can check if GPS is enabled with another library, however I do like the in-app pop up asking the user to turn GPS back on. This dialog is triggered when I run RNLocation.configure
however if you cancel / decline the dialog RNLocation.configure
triggers the above warning.
RNLocation.configure({
distanceFilter: 5.0
})
RNLocation.requestPermission({
ios: "whenInUse",
android: {
detail: "coarse"
}
}).then(granted => {
if (granted) {
console.log("granted")
this.locationSubscription = RNLocation.subscribeToLocationUpdates(locations => {
console.log("获取位置",locations)
/* Example location returned
{
speed: -1,
longitude: -0.1337,
latitude: 51.50998,
accuracy: 5,
heading: -1,
altitude: 0,
altitudeAccuracy: -1
floor: 0
timestamp: 1446007304457.029
}
*/
})
console.log("granted1")
}
})
RNLocation.subscribeToLocationUpdates can't get locations?
It could be better if we do have gps strength level
@matt-oakes first of all thanks for your work :)
Now the question, We just need to get the location when the user use a specific feature of the App, so in that moment we need to get the location and then stop the updating process, so do you think this apporach is good in order to do that and saving phone battery?
RNLocation.requestPermission({
ios: "whenInUse",
android: {
detail: "fine",
rationale: {
title: "Location permission",
message: "We use your location to demo the library",
buttonPositive: "OK",
buttonNegative: "Cancel"
}
}
}).then(granted => {
if (granted) {
this._startUpdatingLocation();
}
});
}
_startUpdatingLocation = () => {
this.locationSubscription = RNLocation.subscribeToLocationUpdates(
locations => {
this.setState({ location: locations[0] });
this._stopUpdatingLocation(); // this was added to stop once I get the location
}
);
};
_stopUpdatingLocation = () => {
this.locationSubscription && this.locationSubscription();
// this.setState({ location: null }); // this was removed for not loose the location
};
Thanks!
Hi,
I found the issue when my app is turn of location service in the settings panel. I have allowed location permission. However, I was turned off my device location service. So the location always null.
How can i check the location settings and open settings panel to user turn on?
Thanks
Hello,
I like this project and we are using it without any issues.
Currently, we are heading a situation where we don't want to have an automatically updated location every time it is changed.
But we want to make it manually on specific situations (screen loaded, etc) because every time is location updated and stored into redux, some "ugly" rerendering is made. We should increase distanceFilter
or compare values in component lifetime cycle method. But it is so clean as should be.
In this package core is some undocumented methods to automatically starting and stopping location updates.
Maybe startUpdatingLocation
and stopUpdatingLocation
should be documented. But still, need to be implemented a trigger to get location manually. And after all, option to enable or disable automatic updating location when RNLocation is configured.
iOS: https://developer.apple.com/documentation/corelocation/cllocationmanager/1620548-requestlocation?language=objc
Android: https://developer.android.com/reference/android/location/LocationManager.html#requestSingleUpdate(java.lang.String,%2520android.location.LocationListener,%2520android.os.Looper)
Take this issue just like a discussion for the feature request.
This is my code to get the last location:
RNLocation.requestPermission({
ios: "whenInUse",
android: {
detail: "coarse"
},
}).then(granted => {
if (granted) {
RNLocation.configure({
distanceFilter: 0, // Meters
});
RNLocation.getLatestLocation({ timeout: 60000 }).then(locations => {
if (locations != null) {
global.longitude = locations.longitude;
global.latitude = locations.latitude;
callback(locations);
}
});
}
});
the locations is null,
also I want to know that how to request the Permission('coarse' and 'fine') simultaneously
I need to track location only when user allows "Always" permission for location tracking. The same functionality as Foursquare app.
The problem is as long as the permission for location tracking is always there is no ticker for location tracking in IOS. When I change permission to "when in use" from settings the ticker start showing. Here I want that the location tracking stops and blue ticker goes away
After doing react-native link I get in xcode the following compilation error:
Duplicate interface definition for class RCTBridge
If I remove the following line from RNLocation.m it works:
#import "RCTBridge.h"
I am using react native version 0.41.2. Could it be related to this version?
I believe this could be a very useful library for the React Native community and I'd like to thank @timfpark for granting me push access to this repository to help with maintenance.
This issue will be a todo list for how we can get the library to a point where it is usable out of the box again. In the future, I will post another issue which includes some post 1.0.0
goals which I think would make this library even more useful. The goal for now is to make which is currently here more stable.
As I said, this is just a start and hopefully we can make this library something even more useful in the future.
Post here if you have any comments or requests.
Hello,
I'm looking into using this library in my Android project. I'm getting an exception in getLatestLocation
when there is more than one location being returned by subscribeToLocationUpdates
. The sort function is treating the location.timestamp
property as a Date
object, but when I inspect it in my debugger, it is simply a number type:
accuracy: 12.479999542236328
altitude: 5
altitudeAccuracy: 40
course: 0
courseAccuracy: 0
latitude: 37.4219983
longitude: -122.084
speed: 0
speedAccuracy: 0
timestamp: 1555098489000
I do not work in background on Android I leave the App in the background stop sending the location even if I have locked the device, in iOS everything works ok.
My configure:
"react-native": "0.57.8"
RNLocation.configure({
distanceFilter: 5.0, // Meters
desiredAccuracy: {
ios: "best",
android: "highAccuracy"
},
// Android only
androidProvider: "auto",
interval: 5000, // Milliseconds
fastestInterval: 10000, // Milliseconds
maxWaitTime: 5000, // Milliseconds
// iOS Only
activityType: "other",
allowsBackgroundLocationUpdates: true,
headingFilter: 1, // Degrees
headingOrientation: "portrait",
pausesLocationUpdatesAutomatically: false,
showsBackgroundLocationIndicator: false,
})
RNLocation.requestPermission({
ios: "always",
android: {
detail: "fine",
rationale: {
title: "Can we access your location?",
message: "Lokate would like to use your location to show you people within a 50 ft distance , that are on the same places as you and if the match is done you can start being friends and chatting. Enter your device settings and change the button of the apps location to allways allow. Close and restart the app again.",
buttonPositive: "OK",
buttonNegative: "Cancel"
}
}
})
How to get the current location?
subscribeToSignificantLocationUpdates
will only fire if there is a change in location, what if I just want the current location.
I didn't see any method for that in the documentation.
Hi,
I have this error: React/RCTBridge.h' file not found
it works on Android, I tried cocoapods without react-native link and with it, just in case, none of them works.
Any help?
Thanks.
https://www.npmjs.com/package/react-native-location references what is perhaps an old name for this library, with different project filenames than specified in the README here.
Hello Tim,
My question is, would it be possible to integrate in the plugin, the CLFloor attribute from CoreLocation ? Here is the docs from Apple for CLFloor :
https://developer.apple.com/documentation/corelocation/clfloor
Thank you.
On simulator background works find but on device I puts console.logs but they not triggered
May you can help me ?
setup a clean project
{
"name": "NatLoc",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-location": "^0.27.0"
},
"devDependencies": {
"babel-jest": "20.0.1",
"babel-preset-react-native": "1.9.2",
"jest": "20.0.1",
"react-test-renderer": "16.0.0-alpha.6"
},
"jest": {
"preset": "react-native"
}
}
installed react-native-location
linked
and compile in xcode
gives errors (just showing a few)
../react-native/React/Base/RCTBridge.h:66:12: note: previous definition is here
@interface RCTBridge : NSObject
^
^
@Property (nonatomic, copy, readonly) NSArray *moduleClasses;
^
: error: property has a previous declaration
@Property (nonatomic, strong, readonly) NSURL *bundleURL;
^
error: property has a previous declaration
@Property (nonatomic, strong) Class executorClass;
^
In file included from /Users/pierrejean/Dropbox/dev-app/NatLoc/node_modules/react-native-location/RNLocation.m:3:
../react-native/React/Base/RCTBridge.h:166:37: note: property declared here
@Property (nonatomic, strong) Class executorClass;
^
error: property has a previous declaration
@Property (nonatomic, weak, readonly) id delegate;
^
error: property has a previous declaration
@Property (nonatomic, copy, readonly) NSDictionary *launchOptions;
^
error: property has a previous declaration
@Property (nonatomic, readonly, getter=isLoading) BOOL loading;
^
error: property has a previous declaration
@Property (nonatomic, readonly, getter=isValid) BOOL valid;
^
error: property has a previous declaration
@Property (nonatomic, readonly, weak) JSContext *jsContext;
^
error: property has a previous declaration
@Property (nonatomic, readonly, strong) RCTPerformanceLogger *performanceLogger;
^
^
4 warnings and 10 errors generated.
Build failed 2017-05-14, 12:50 PM
Getting this error after manually linking on Android:
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :react-native-location.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :react-native-location.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :react-native-location.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :react-native-location.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :react-native-location.
Show Details
Affected Modules: app
My setup:
"react-native": "0.59.8"
"react-native-location": "^2.2.0"
"react-native-router-flux": "^4.1.0-beta.5"
after clicking allow or refuse permission on the permission dialog in emulator android Q, the app will crash
but it works fine on lower android version,
maybe we can check if something has changed on Q that the library need to handle?
or maybe just the Q on emulator is still not so stable?
any thoughts?
Is there some way to limit the frequency (number of seconds) for how often heading gets updated?
Thank you!
On iOS, after Don't allow permission. I cannot request permission again. How can i do it?
Great library. This has been super useful to me.
I'm still a bit of a react-native newbie, but I was wondering if there's a reason why docs have us get Location via
var { RNLocation: Location } = require('NativeModules');
instead of
var Location = require('react-native-location');
The second approach seems both more clear, and allows me to mock this more easily in jest, i.e.
jest.mock('react-native-location', () => ({
requestAlwaysAuthorization() {},
startUpdatingLocation() {}
// etc
})) ;
When I try to get my location ,the accuracy value that I obtained is always 2000, it never changed. Is there any bugs have to be fixed or I am doing wrong somethink ?
Will this library be updated to support iOS 11?
Running in iOS 11 currently and apparently no location data is recorded.
react-native: 0.44.0
react-native-location: 0.27.0
I get authorization = "denied" for new installed app but with location service disabled!
shouldn't i get "not determined" status??!?!
or
how should i get location service status from your package?!
I'm looking at this right now and it's unclear what "location" returns. Can you add that to the README?
For example, is it 'latitude' and 'longitude'? Is there a city name? Is it this data? https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/
Specifically this part of the README could be improved:
var subscription = DeviceEventEmitter.addListener(
'locationUpdated',
(location) => {
/**
Location will be of the form:
{'lat': ..., 'long': ..., etc}
}
);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.