michalchudziak / react-native-geolocation Goto Github PK
View Code? Open in Web Editor NEWGeolocation APIs for React Native
License: MIT License
Geolocation APIs for React Native
License: MIT License
Is there a way to get the user current physcal address (Reverse Geocoding) using this library?
If so, can someone spare some code on how to do that?
The README references a MIT license and that it's located in LICENSES, which doesn't exist.
Hello!
As almost everybody here, I'm trying to capture device`s geolocation intending to track my company cars when delivering.
For that, I'm using Geolocation.watchposition and it's working very well on IOS and most part of android devices I've been testing. However, and only on Samsung devices with Knox Library, the location services stop working when I lock ou minimize my app. When it comes to foreground, everything gets working again, but I loose every coordinate I got when locked ou in background.
Would someone know whats the catch?
10x in advance for any help
iOS
- react-native-geolocation:1.4.2
- react-native:0.58.4
- react:16.6.3
I am using Geolocation.getCurrentPosition method for getting current latitude and longitude and I am getting heading value as -1 in iOS whereas in android it working fine.
How to get the correct heading value to rotate the marker.
Geolocation.getCurrentPosition(info => {
console.log("Geolocation",info)
});
I tried both the automatic and the manual installations for iOS, but I always get an error 'React/RCTEventEmitter.h' file not found
in RNCGeolocation.h
when building the project. I've cleaned the build folder, removed and reinstalled my pods, but nothing I do seems to make any difference ๐ฌ when I undo all my changes, the project builds fine.
I'm on [email protected] and [email protected]
React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 700.40 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.4.1 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.5.0 - /usr/local/bin/npm
Watchman: 4.7.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 23, 25, 26, 27, 28
Build Tools: 25.0.2, 27.0.3, 28.0.3, 29.0.0
System Images: android-27 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.5429.30.34.5452501
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.8 => 0.59.8
npmGlobalPackages:
react-native-cli: 1.0.0
Issue in typings, so not platform related.
The typings
directory is missing from node_modules/@react-native-community/geolocation
after updating to 1.4.0. Works as expected when downgrading back to 1.3.0
System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
Memory: 21.92 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.12.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
Android SDK:
API Levels: 28, 29
Build Tools: 28.0.3, 29.0.1
System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
npmPackages:
react: 16.10.2 => 16.10.2
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-cli: 2.0.1
iOS
Hi,
I'm getting a problem with getting location on iOS, tested on both iOS 12 and 13, real iPhone 7 and iPhone 8 and 11 Pro in the simulator.
My issue is that getCurrentPosition only works the first time I request it, after that one time it begins timming out on all requests, and watchPosition only works two/three consecutive times, and then stops giving more position changes.
Currently the library roughly mirrors the web Geolocation API spec. We are already break away from it in some places such as the options which are available.
I think that there are currently some issues with the API which makes it not suitable for use in this library.
watchPosition
You can make multiple calls to watchPosition
with different options. With the current API it is not clear that each listener will actually be called with the options from the last call to watchPosition
. This is because the location APIs on both Android and iOS have settings which are global to the app and not per listener. We should not try and fight against this with our library and instead make it clear from the API that settings are for all listeners.
unsubscribe
function when calling watchPosition
It's common practice to return a function when creating a listener which can be called to remove the listener. Like this:
const subscription = Geolocation.watchPosition(...);
// later
subscription.remove();
This is a minor change, but a breaking one and not a show stopper to not include it.
What do we think about changing the API in some way? How much to we want to stick to the web API given the differences on mobile?
Look in your Readme
I'm having a permission error when picking up the user's location.
{TIMEOUT: 3, POSITION_UNAVAILABLE: 2, PERMISSION_DENIED: 1, message: "Location request timed out", code: 3}
My code:
componentDidMount() {
Geolocation.getCurrentPosition(info => console.log(info));
}
android.manifest:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Does anyone know what else it can be?
**$ ./gradlew assembleRelease
Configure project :react-native-webview
:react-native-webview:reactNativeAndroidRoot E:\RN\st-react-native\node_modules\react-native\android
Task :@react-native-community_geolocation:compileReleaseJavaWithJavac FAILED
E:\RN\st-react-native\node_modules@react-native-community\geolocation\android\src\main\java\com\reactnativecommunity\geolocation\GeolocationModule.java:21: error: package android.support.v4.content does not exist
import android.support.v4.content.ContextCompat;
^**
the situation was fixed by replacing the string
import android.support.v4.content.ContextCompat;
on
import androidx.core.content.ContextCompat;
React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 511.38 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.12.0 - /usr/local/bin/node
Yarn: 1.10.1 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 22, 23, 24, 25, 26, 27, 28
Build Tools: 27.0.3, 28.0.2, 28.0.3, 29.0.0
System Images: android-22 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: ^16.8.3 => 16.8.3
react-native: ^0.59.9 => 0.59.9
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
react-native-log-ios: 1.0.1
react-native-version: 2.7.0
react-native: 0.57.1
Android
The permissions alert consistently pops up twice in a row when a user does not have location permissions enabled and answers "deny" on the first alert.
Here is the code I'm using to check for location permissions. This is a helper function outside of my main React component library.
const checkLocationPermissions = async () => {
const location = PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION;
try {
const granted = await PermissionsAndroid.request( location );
if ( granted === PermissionsAndroid.RESULTS.GRANTED ) {
return true;
}
return JSON.stringify( granted );
} catch ( err ) {
return err;
}
};
Then, in my component, I'm checking for location permissions like this:
requestAndroidPermissions() {
if ( Platform.OS === "android" ) {
checkLocationPermissions().then( ( granted ) => {
if ( granted ) {
this.getGeolocation();
} else {
this.setError( "location" );
}
} );
} else {
this.getGeolocation();
}
}
This happens in three different places where I check for location in the app & is consistent across newer and older Android devices.
Hello,
I want to get user location but not want request a permission. Because I have my own logic.
Is it possible to prevent Geolocation from requesting permission?
Thank you,
AndroidX will replace the Support Libraries.
AndroidX is the open-source project that the Android team uses to develop, test, package, version and release libraries within Jetpack.
AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS and provides backwards-compatibility across Android releases. AndroidX fully replaces the Support Library by providing feature parity and new libraries.
See: https://developer.android.com/jetpack/androidx/
AndroidX is the replacement for Google Support Libraries. Android P is the transition phase for this. The next version of Android is likely to support only AndroidX. This library fails on android builds that use the new compileSdkVersion.
Environment:
OS: macOS High Sierra 10.13.6
Node: 8.11.2
Yarn: 1.9.4
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 10.1 Build version 10B61
Android Studio: 3.3 AI-182.5107.16.33.5314842
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.4 => 0.55.4
When you call Geolocation.requestAuthorization();
from Android you get a error screen. maybe this method is only intended for iOS ?
Just adding this line will get it to crash
In the documentation you can see :
Android API >= 18 Positions will also contain a mocked boolean to indicate if position was created from a mock provider.
Android API >= 23 Requires an additional step to check for, and request the ACCESS_FINE_LOCATION permission using the PermissionsAndroid API. Failure to do so may result in a hard crash.
But as it is the library is asking for the permissions itself so we don't need to do anything more than just call Geolocation.getCurrentPosition
like in the integrated version from before no ?
Thanks a lot
ReactNative: 0.57.8
react: 16.6.3
@react-native-community/geolocation: 1.4.2
I have configured location permissions๏ผ'ACCESS_FINE_LOCATION' in AndroidManifest.xml,
but GPS doesn't work in some android systems๏ผLocation request timed out
PERMISSION_DENIED: 1
POSITION_UNAVAILABLE: 2
TIMEOUT: 3
code: 3
message: "Location request timed out"
Does the library handle network error, while finding the location?
I am switching off the Internet, while searching the geolocation and the error callback isn't invoked only on iOS.
My config:
GeolocationService.getCurrentPosition(
(geoPosition: GeoPosition) => {
console.log(geoPosition);
},
error => {
setIsLoading(false);
},
{ enableHighAccuracy: true, timeout: 1000, maximumAge: 10000 }
);
What is the best way to test location change functionality in simulator and/or on device?
To use the native geolocation APIs correctly and in a battery efficient way, you need to be able to tweak the location settings. Currently, only a small subset of the options are exposed. We should extend this to ensure all options are present and they have sensible defaults (matching current defaults to avoid breaking changes, if possible).
A partial list of the options is here:
https://github.com/timfpark/react-native-location/blob/master/README.md#rnlocationconfigure
Some of these are specific to each platform and some have the same meaning, but different values. We should take that into account when adding these options.
System:
OS: macOS 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 1.33 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.1 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.10.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 25, 28
Build Tools: 28.0.3
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.3 => 0.60.3
npmGlobalPackages:
react-native-cli: 2.0.1
Jest - Android and iOS working
After adding Geolocation to the Project the tests are working. Import Geolocation and use it somewhere will fail the test. The test is standard of the CLI-Init project.
All other files are the ones which will be generated automatically.
Linking and everthing is right as far as I can tell.
react-native init Repo1
class App extends React.Component {
state = {
longitude: null,
latitude: null,
}
componentDidMount() {
//PermissionsAndroid.request(
// PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
// {
// title: "Location Accessing Permission",
// message: "App needs access to your location"
// }
//);
Geolocation.getCurrentPosition(
(success) => {
this.setState(
{longitude: success.coords.longitude,
latitude: success.coords.latitude}
)
},
(err) => {console.log(err);}
);
}
// https://facebook.github.io/react-native/docs/geolocation#getcurrentposition
render(){
return (
<View>
<Text>Latitude: {this.state.latitude}</Text>
<Text>Longitude: {this.state.longitude}</Text>
</View>
)
}
};
Last Step: run yarn test
and the following Error appears:
yarn test
yarn run v1.13.0
$ jest
FAIL __tests__/App-test.js
โ Test suite failed to run
@react-native-community/geolocation: NativeModule.RNCGeolocation is null. To fix this issue try these steps:
โข Run `react-native link @react-native-community/geolocation` in the project root.
โข Rebuild and re-run the app.
โข If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-geolocation
at Object.<anonymous> (node_modules/@react-native-community/geolocation/lib/commonjs/nativeInterface.js:17:9)
at Object.<anonymous> (node_modules/@react-native-community/geolocation/lib/commonjs/implementation.native.js:11:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 3.145s
Ran all test suites.
error Command failed with exit code 1.
Githublink for an example: https://github.com/SergejDK/ReactNativeJestGeolocationRepo
As discussed, we should migrate from android.location API. I'd like to use this issue to start the discussion on potential alternatives.
Reference libraries:
react-native 0.60
xcode 10.3
I installed the module using npm and now I am getting the same error as I was getting previously -
ld: library not found for -lRCTGeolocation
I tried manually linking it but it still fails. I get this error only when I try to run on my ios device through xcode or cli like react-native run-ios --device "iPhone"
.
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
Memory: 1.17 GB / 7.91 GB
Binaries:
Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
SDKs:
Android SDK:
Android NDK: 20.0.5594570
Android, not tested on iOs
- Android:5.1
- iOS:-
- react-native-geolocation:^2.0.2
- react-native:0.60.5
- react:16.8.6
I am trying to use the react-native localization module by using the command yarn add @ react-native-community / geolocation
it adds to the module but at the time of use it prints this error message could anyone help?
this mensage error
@react-native-community/geolocation:NativeModule.RNCGeolocation is null.
To fix this issue try these steps:
Run `react-native link@react-native-community/geolocation` in the
project root.
Rebuild and re-un the app.
if you are using CocoaPods on iOs, run `pod install` in the `ios` direc
tory and then rebuild and re-un the app. You may also need to re-open
Xcode to get the new pods
If none of these fix the issue, please open an issue on the github
repository:https://github.com/react-native-community/react-native-geolocation
note I already did the steps but it didn't work
this image
https://ibb.co/Ht8ydmR
to reproduce the error just import the module into the project
import AsyncStorage from '@react-native-community/async-storage';
import Geolocation from '@react-native-community/geolocation';
import {navigate} from '../../../services/navigation';
import {PositionLoadingActivityOn} from './action';
function* myGenerator() {
yield console.tron.log('test');
}
export default all([takeLatest('@position/REQUEST_POSITION', myGenerator)]);
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 32.03 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.3 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.10.3 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
Android SDK:
API Levels: 28
Build Tools: 26.0.2, 27.0.3, 28.0.3, 29.0.1
System Images: android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5791312
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.5 => 0.60.5
npmGlobalPackages:
react-native-cli: 2.0.1
This is for android only
I just started to use React native community geolocation. It works fine with iOS, but for android it gives me these errors:
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/node_modules/@react-native-community/geolocation/android/src/main/java/com/reactnativecommunity/geolocation/GeolocationModule.java:33: error: package com.facebook.react.module.annotations does not exist
import com.facebook.react.module.annotations.ReactModule;
/node_modules/@react-native-community/geolocation/android/src/main/java/com/reactnativecommunity/geolocation/GeolocationModule.java:35: error: package com.facebook.react.modules.permissions does not exist
import com.facebook.react.modules.permissions.PermissionsModule;
^
/node_modules/@react-native-community/geolocation/android/src/main/java/com/reactnativecommunity/geolocation/GeolocationModule.java:42: error: cannot find symbol
@ReactModule(name = GeolocationModule.NAME)
^
symbol: class ReactModule
/node_modules/@react-native-community/geolocation/android/src/main/java/com/reactnativecommunity/geolocation/GeolocationModule.java:128: error: cannot find symbol
final PermissionsModule perms = getReactApplicationContext().getNativeModule(PermissionsModule.class);
^
symbol: class PermissionsModule
location: class GeolocationModule
/node_modules/@react-native-community/geolocation/android/src/main/java/com/reactnativecommunity/geolocation/GeolocationModule.java:128: error: cannot find symbol
final PermissionsModule perms = getReactApplicationContext().getNativeModule(PermissionsModule.class);
^
symbol: class PermissionsModule
location: class GeolocationModule
5 errors
I tried cleaning, rebuilding, reinstalling node modules, etc. Nothing works. However, in Android studio, I do see this error in the "Sync":
ERROR: The modules ['@react-native-community_geolocation', 'react-native-community-geolocation'] point to the same directory in the file system.
Each module must have a unique path.
Not sure if this is related or a completely different problem.
I didn't do much to get this error, just npm installed react-native-community/geolocation and followed the instructions
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 269.32 MB / 32.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.0 - /usr/local/bin/node
Yarn: 1.12.3 - ~/.npm-packages/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.1, 27.0.3, 28.0.3
System Images: android-25 | Google APIs ARM 64 v8a, android-25 | Google APIs ARM EABI v7a, android-25 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom_64
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5314842
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.1 => 0.59.1
Android
Using Geolocation.getCurrentPosition
on Android, when the user selects 'deny' when asked for permission to access the device's location, the fail callback is never called:
const getCurrentPosition = () => {
return new Promise((resolve, reject) => {
Geolocation.getCurrentPosition(
({ coords }) => {
const { latitude, longitude } = coords;
resolve({ latitude, longitude });
},
err => {
console.log(err);
reject(err);
},
{
enableHighAccuracy: false,
timeout: 3000
}
);
});
};
getCurrentPosition();
We need to set up continuous integration for this repo. I'd like to start with the following checks:
https://github.com/react-native-community/react-native-slider/blob/master/.circleci/config.yml
What went wrong:
Execution failed for task ':@react-native-community_geolocation:generateDebugRFile'.
java.nio.file.NoSuchFileException: /Users/serhatyilmaz/Desktop/development/react/TaxiBookingApp/node_modules/@react-native-community/geolocation/android/build/intermediates/merged_man?fests/debug/../../l?brary_man?fest/debug/AndroidManifest.xml
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.8 => 0.59.8
npmGlobalPackages:
eslint-plugin-react-native: 3.2.1
react-native-cli: 2.0.1
Android and iOS
import Geolocation from '@react-native-community/geolocation'
imports the index.js instead of index.native.js, resulting in "method not supported by the browser" errors even on Android and iOS devices
Looks like we still need to run react-native link, will it be possible to use auto linking soon?
Hi React Native Community,
I'm probably one of a handful of developers building react native for tvOS and would like to use Geolocation services (think like an Apple TV weather app). Any thoughts on how to either integrate the existing module or access location information in a react native tvOS project?
James
I am using the getCurrentPosition() method of the library. I wish to show accuracy of the location in my app. The method returns accuracy but i am unsure the unit of the accuracy. Is it some kind of a percentage or meters(like whatsapp). Kindly help.
System:
OS: macOS Mojave 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 387.96 MB / 32.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
Android SDK:
API Levels: 23, 26, 27, 28
Build Tools: 27.0.3, 28.0.3
System Images: android-27 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.1 => 0.61.1
npmGlobalPackages:
react-native-cli: 2.0.1
Both
When running app on RN 0.61.1, I encounter this error in the debug console Error: @react-native-community/geolocation: NativeModule.RNCGeolocation is null.
Run project after yarn and pod install, open debug console
React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 2.02 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
Yarn: 1.13.0 - ~/.nvm/versions/node/v10.13.0/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.13.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 23, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.2, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.2, 27.0.3, 28.0.3
System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-26 | Google Play Intel x86 Atom, android-27 | Google APIs Intel x86 Atom
IDEs:
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.1 => 0.59.1
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-vector-icons: 6.1.0
iOS
While trying to build on iOS, the module logError cannot be found.
We should deprecate and remove the requestAuthorization
method from this library. This is currently a broken implementation as it does not allow you to specific what level of permissions you would like on iOS and doesn't do anything at all on Android.
I think that we should instead be asking users to use a dedicated API for managing permissions. react-native-permissions
is a good example, but really React Native should have a cross platform API for this builtin, rather than just supporting Android through PermissionsAndroid
.
Am I the only one ? In the emulator, it works fine but on my own device, it's impossible to find the location.
Can someone help me ? Thanks.
react-native-community/geolocation : 2.0.2
react-native : 0.60.5
I am using RN 0.60, Xcode 10.2.
Package.json : "@react-native-community/geolocation": "^1.4.2"
Podfile : pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation'
My Android app is running fine, but on Xcode I get error
undefined is not an object (evaluating 'navigator.geolocation.getCurrentPosition')
As it is running fine on android I assume it is IOS installation issue.
Steps I followed
<key>NSLocationWhenInUseUsageDescription</key> <string>Get current location</string>
pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation'
to pod fileNo luck, any help ?? can anybody tell me where I am going wrong ?
It is giving error for this function navigator.geolocation.getCurrentPosition
iOS
Missing Purpose String in Info.plist File - Your app's code references one or more APIs that access sensitive user data. The app's Info.plist file should contain a
NSLocationAlwaysUsageDescription
key with a user-facing purpose string explaining clearly and completely why your app needs the data.
We get the above warning email from Apple store. I use LocationWhenInUseUsageDescription
but not NSLocationAlwaysAndWhenInUseUsageDescription
and NSLocationAlwaysUsageDescription
. In other terms we want location data only when app is in the foreground not in background.
Things i tried
NSLocationAlwaysAndWhenInUseUsageDescription
and NSLocationAlwaysUsageDescription
. But this library uses the always permission when the strings are present, but we don't want those permission.What is the best way to handle this situation?
Add typescript typing in to npm
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-native/index.d.ts
None
React Native Environment Info:
System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 1.05 GB / 7.86 GB
Binaries:
Node: 10.16.0 - D:\Programs\Node.js\node.EXE
npm: 6.9.0 - D:\Programs\Node.js\npm.CMD
Android
When I run react-native run-android
I got this error:
Task :@react-native-community_geolocation:compileDebugJavaWithJavac FAILED
D:\Projects\project\node_modules\@react-native-community\geolocation\android\src\main\java\com\reactnativecommunity\geolocation\GeolocationModule.java:21: error: package android.support.v4.content does not exist
import android.support.v4.content.ContextCompat;
^
D:\Projects\project\node_modules\@react-native-community\geolocation\android\src\main\java\com\reactnativecommunity\geolocation\GeolocationModule.java:274: error: cannot find symbol
int finePermission = ContextCompat.checkSelfPermission(getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION);
^
symbol: variable ContextCompat
location: class GeolocationModule
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':@react-native-community_geolocation:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Content of android/app/build.gradle:
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 28
buildToolsVersion "29.0.0-rc3"
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
defaultConfig {
applicationId "com.project"
minSdkVersion 16
targetSdkVersion 28
versionCode 96
versionName "1.51.15"
ndk {
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a":3, "x86_64":4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':@react-native-community_geolocation')
implementation project(':@react-native-community_netinfo')
compile project(':react-native-static-server')
compile project(':react-native-keep-awake')
compile project(':react-native-file-viewer')
compile project(':react-native-webview')
compile project(':react-native-zip-archive')
compile project(':rn-fetch-blob')
compile project(':react-native-fs')
compile project(':react-native-spatial')
compile project(':react-native-fs')
compile project(':react-native-sqlite-2')
compile 'com.google.android.gms:play-services-location:+'
compile project(':react-native-sensitive-info')
compile project(':react-native-sentry')
compile project(':react-native-image-picker')
compile project(':react-native-device-settings')
compile project(':react-native-linear-gradient')
compile project(':react-native-vector-icons')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.facebook.fresco:fresco:1.9.0'
compile 'com.facebook.fresco:animated-gif:1.9.0'
// IN CASE YOU NEED WEBP SUPPORT / MAKE SURE TO CHANGE THIS TOO TO 1.9.0
compile 'com.facebook.fresco:animated-webp:1.9.0'
compile 'com.facebook.fresco:webpsupport:1.9.0'
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
task copyFonts(type: Copy) {
from '../../assets/fonts'
into 'src/main/assets/fonts'
}
// Copy map.html and its files
task copyMapHTML(type: Copy) {
from '../../src/components/presentational/OLMap/webview/map.html'
into 'src/main/assets/OLMap'
}
task copyMapSRC(type: Copy) {
from '../../assets/src/components/presentational/OLMap/webview'
into 'src/main/assets/OLMap'
}
task copyLogo(type: Copy) {
from '../../assets/images/login_logo.png'
into 'src/main/assets'
}
// Note that you may need to add other build variants
gradle.projectsEvaluated {
bundleDebugJsAndAssets.dependsOn([copyMapHTML, copyMapSRC, copyFonts, copyLogo])
bundleReleaseJsAndAssets.dependsOn([copyMapHTML, copyMapSRC, copyFonts, copyLogo])
}
How I can get location when app in background? Actually work when app in first plane, greetings
Android
> Could not resolve all task dependencies for configuration ':react-native-geolocation-service:debugCompileClasspath'.
> Could not resolve com.android.support:appcompat-v7:28.0.0.
Required by:
project :react-native-geolocation-service
> Cannot find a version of 'androidx.appcompat:appcompat' that satisfies the version constraints:
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'com.android.support:appcompat-v7:28.0.0' because of the following reason: ENABLE_JETIFIER is enabled
Constraint path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'com.facebook.react:react-native:0.60.0' --> 'androidx.appcompat:appcompat:1.0.2'
> Could not resolve androidx.appcompat:appcompat:{strictly 1.0.0}.
Required by:
project :react-native-geolocation-service
> Cannot find a version of 'androidx.appcompat:appcompat' that satisfies the version constraints:
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'com.android.support:appcompat-v7:28.0.0' because of the following reason: ENABLE_JETIFIER is enabled
Constraint path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'com.facebook.react:react-native:0.60.0' --> 'androidx.appcompat:appcompat:1.0.2'
> Could not resolve androidx.core:core:{strictly 1.0.0}.
Required by:
project :react-native-geolocation-service
> Cannot find a version of 'androidx.core:core' that satisfies the version constraints:
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.core:core:1.0.1'
Constraint path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.core:core:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.legacy:legacy-support-core-utils:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.vectordrawable:vectordrawable:1.0.1' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'com.google.android.gms:play-services-location:11.4.2' --> 'com.google.android.gms:play-services-basement:11.4.2' --> 'androidx.legacy:legacy-support-v4:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.legacy:legacy-support-core-utils:1.0.0' --> 'androidx.loader:loader:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'com.google.android.gms:play-services-location:11.4.2' --> 'com.google.android.gms:play-services-basement:11.4.2' --> 'androidx.legacy:legacy-support-v4:1.0.0' --> 'androidx.media:media:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.customview:customview:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.viewpager:viewpager:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.coordinatorlayout:coordinatorlayout:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.drawerlayout:drawerlayout:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.slidingpanelayout:slidingpanelayout:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' --> 'androidx.core:core:1.0.0'
Dependency path 'MeetMore:react-native-geolocation-service:unspecified' --> 'androidx.appcompat:appcompat:1.0.2' --> 'androidx.fragment:fragment:1.0.0' --> 'androidx.legacy:legacy-support-core-ui:1.0.0' --> 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0' --> 'androidx.core:core:1.0.0'
Android
Function Geolocation.getCurrentPosition
always returns error on Android
Location request timed out
{ "PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Location request timed out" }
I've tried to add timeout
and maximumAge
options but it doesn't help me.
return new Promise(resolve => {
Geolocation.getCurrentPosition(
position => {
const { latitude, longitude } = position.coords;
resolve({ latitude, longitude });
},
err => resolve(err),
{
enableHighAccuracy: true,
timeout: 100,
maximumAge: 0,
}
);
});
i am a final year student in mechanical engineering.. but for my final year project i have been assigned to develop apps for android for iot use. i understand nothing about all this. i just get the coding from github for meter gauge. can someone help me what is wrong with this.
java-
package ise.uitm;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
public class CustomGauge extends View {
private static final int DEFAULT_LONG_POINTER_SIZE = 1;
private Paint mPaint;
private float mStrokeWidth;
private int mStrokeColor;
private RectF mRect;
private String mStrokeCap;
private int mStartAngle;
private int mSweepAngle;
private int mStartValue;
private int mEndValue;
private int mValue;
private double mPointAngle;
private int mPoint;
private int mPointSize;
private int mPointStartColor;
private int mPointEndColor;
private int mDividerColor;
private int mDividerSize;
private int mDividerStepAngle;
private int mDividersCount;
private boolean mDividerDrawFirst;
private boolean mDividerDrawLast;
public CustomGauge(Context context) {
super(context);
init();
}
public CustomGauge(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, ise.uitm.gauge2.R.styleable.CustomGauge, 0, 0);
// stroke style
setStrokeWidth(a.getDimension(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeStrokeWidth, 10));
setStrokeColor(a.getColor(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeStrokeColor, ContextCompat.getColor(context, android.R.color.darker_gray)));
setStrokeCap(a.getString(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeStrokeCap));
// angle start and sweep (opposite direction 0, 270, 180, 90)
setStartAngle(a.getInt(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeStartAngle, 0));
setSweepAngle(a.getInt(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeSweepAngle, 360));
// scale (from mStartValue to mEndValue)
setStartValue(a.getInt(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeStartValue, 0));
setEndValue(a.getInt(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeEndValue, 1000));
// pointer size and color
setPointSize(a.getInt(ise.uitm.gauge2.R.styleable.CustomGauge_gaugePointSize, 0));
setPointStartColor(a.getColor(ise.uitm.gauge2.R.styleable.CustomGauge_gaugePointStartColor, ContextCompat.getColor(context, android.R.color.white)));
setPointEndColor(a.getColor(ise.uitm.gauge2.R.styleable.CustomGauge_gaugePointEndColor, ContextCompat.getColor(context, android.R.color.white)));
// divider options
int dividerSize = a.getInt(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeDividerSize, 0);
setDividerColor(a.getColor(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeDividerColor, ContextCompat.getColor(context, android.R.color.white)));
int dividerStep = a.getInt(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeDividerStep, 0);
setDividerDrawFirst(a.getBoolean(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeDividerDrawFirst, true));
setDividerDrawLast(a.getBoolean(ise.uitm.gauge2.R.styleable.CustomGauge_gaugeDividerDrawLast, true));
// calculating one point sweep
mPointAngle = ((double) Math.abs(mSweepAngle) / (mEndValue - mStartValue));
// calculating divider step
if (dividerSize > 0) {
mDividerSize = mSweepAngle / (Math.abs(mEndValue - mStartValue) / dividerSize);
mDividersCount = 100 / dividerStep;
mDividerStepAngle = mSweepAngle / mDividersCount;
}
a.recycle();
init();
}
private void init() {
//main Paint
mPaint = new Paint();
mPaint.setColor(mStrokeColor);
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setAntiAlias(true);
if (!TextUtils.isEmpty(mStrokeCap)) {
if (mStrokeCap.equals("BUTT"))
mPaint.setStrokeCap(Paint.Cap.BUTT);
else if (mStrokeCap.equals("ROUND"))
mPaint.setStrokeCap(Paint.Cap.ROUND);
} else
mPaint.setStrokeCap(Paint.Cap.BUTT);
mPaint.setStyle(Paint.Style.STROKE);
mRect = new RectF();
mValue = mStartValue;
mPoint = mStartAngle;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float padding = getStrokeWidth();
float size = getWidth()<getHeight() ? getWidth() : getHeight();
float width = size - (2*padding);
float height = size - (2*padding);
// float radius = (width > height ? width/2 : height/2);
float radius = (width < height ? width/2 : height/2);
float rectLeft = (getWidth() - (2*padding))/2 - radius + padding;
float rectTop = (getHeight() - (2*padding))/2 - radius + padding;
float rectRight = (getWidth() - (2*padding))/2 - radius + padding + width;
float rectBottom = (getHeight() - (2*padding))/2 - radius + padding + height;
mRect.set(rectLeft, rectTop, rectRight, rectBottom);
mPaint.setColor(mStrokeColor);
mPaint.setShader(null);
canvas.drawArc(mRect, mStartAngle, mSweepAngle, false, mPaint);
mPaint.setColor(mPointStartColor);
mPaint.setShader(new LinearGradient(getWidth(), getHeight(), 0, 0, mPointEndColor, mPointStartColor, Shader.TileMode.CLAMP));
if (mPointSize>0) {//if size of pointer is defined
if (mPoint > mStartAngle + mPointSize/2) {
canvas.drawArc(mRect, mPoint - mPointSize/2, mPointSize, false, mPaint);
}
else { //to avoid excedding start/zero point
canvas.drawArc(mRect, mPoint, mPointSize, false, mPaint);
}
}
else { //draw from start point to value point (long pointer)
if (mValue==mStartValue) //use non-zero default value for start point (to avoid lack of pointer for start/zero value)
canvas.drawArc(mRect, mStartAngle, DEFAULT_LONG_POINTER_SIZE, false, mPaint);
else
canvas.drawArc(mRect, mStartAngle, mPoint - mStartAngle, false, mPaint);
}
if (mDividerSize > 0) {
mPaint.setColor(mDividerColor);
mPaint.setShader(null);
int i = mDividerDrawFirst ? 0 : 1;
int max = mDividerDrawLast ? mDividersCount + 1 : mDividersCount;
for (; i < max; i++) {
canvas.drawArc(mRect, mStartAngle + i* mDividerStepAngle, mDividerSize, false, mPaint);
}
}
}
public void setValue(int value) {
mValue = value;
mPoint = (int) (mStartAngle + (mValue-mStartValue) * mPointAngle);
invalidate();
}
public int getValue() {
return mValue;
}
@SuppressWarnings("unused")
public float getStrokeWidth() {
return mStrokeWidth;
}
public void setStrokeWidth(float strokeWidth) {
mStrokeWidth = strokeWidth;
}
@SuppressWarnings("unused")
public int getStrokeColor() {
return mStrokeColor;
}
public void setStrokeColor(int strokeColor) {
mStrokeColor = strokeColor;
}
@SuppressWarnings("unused")
public String getStrokeCap() {
return mStrokeCap;
}
public void setStrokeCap(String strokeCap) {
mStrokeCap = strokeCap;
if(mPaint != null) {
if (mStrokeCap.equals("BUTT")) {
mPaint.setStrokeCap(Paint.Cap.BUTT);
} else if (mStrokeCap.equals("ROUND")) {
mPaint.setStrokeCap(Paint.Cap.ROUND);
}
}
}
@SuppressWarnings("unused")
public int getStartAngle() {
return mStartAngle;
}
public void setStartAngle(int startAngle) {
mStartAngle = startAngle;
}
@SuppressWarnings("unused")
public int getSweepAngle() {
return mSweepAngle;
}
public void setSweepAngle(int sweepAngle) {
mSweepAngle = sweepAngle;
}
@SuppressWarnings("unused")
public int getStartValue() {
return mStartValue;
}
public void setStartValue(int startValue) {
mStartValue = startValue;
}
@SuppressWarnings("unused")
public int getEndValue() {
return mEndValue;
}
public void setEndValue(int endValue) {
mEndValue = endValue;
mPointAngle = ((double) Math.abs(mSweepAngle) / (mEndValue - mStartValue));
invalidate();
}
@SuppressWarnings("unused")
public int getPointSize() {
return mPointSize;
}
public void setPointSize(int pointSize) {
mPointSize = pointSize;
}
@SuppressWarnings("unused")
public int getPointStartColor() {
return mPointStartColor;
}
public void setPointStartColor(int pointStartColor) {
mPointStartColor = pointStartColor;
}
@SuppressWarnings("unused")
public int getPointEndColor() {
return mPointEndColor;
}
public void setPointEndColor(int pointEndColor) {
mPointEndColor = pointEndColor;
}
@SuppressWarnings("unused")
public int getDividerColor() {
return mDividerColor;
}
public void setDividerColor(int dividerColor) {
mDividerColor = dividerColor;
}
@SuppressWarnings("unused")
public boolean isDividerDrawFirst() {
return mDividerDrawFirst;
}
public void setDividerDrawFirst(boolean dividerDrawFirst) {
mDividerDrawFirst = dividerDrawFirst;
}
@SuppressWarnings("unused")
public boolean isDividerDrawLast() {
return mDividerDrawLast;
}
public void setDividerDrawLast(boolean dividerDrawLast) {
mDividerDrawLast = dividerDrawLast;
}
public void setDividerStep(int dividerStep){
if (dividerStep > 0) {
mDividersCount = 100 / dividerStep;
mDividerStepAngle = mSweepAngle / mDividersCount;
}
}
public void setDividerSize(int dividerSize) {
if (dividerSize > 0) {
mDividerSize = mSweepAngle / (Math.abs(mEndValue - mStartValue) / dividerSize);
}
}
}
gradle-
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "pl.pawelkleczkowskicustomgauge"
minSdkVersion 15
targetSdkVersion 28
versionCode 4
versionName "1.0.4"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':gauge2')
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
System:
OS: macOS 10.14.4
CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
Memory: 34.32 MB / 8.00 GB
Shell: 3.0.2 - /usr/local/bin/fish
Binaries:
Node: 12.3.1 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 23, 25, 26, 28
Build Tools: 28.0.3
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5522156
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.0 => 0.60.0
npmGlobalPackages:
eslint-plugin-react-native: 3.7.0
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
Android
brand new project
"SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/dan/Workspace/app/android/local.properties'."
react-native run-android
It always returs the cache value of geolocation...
Web support. Given the geolocation API will no longer be hanging off navigator
in React Native, we would need a web implementation of this module to maintain cross-platform support for geolocation on web.
Native browser implementation that the RN implementation was based upon:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API
cc @EvanBacon
System:
OS: macOS 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Memory: 54.35 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.16.1 - /usr/local/bin/node
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
Android SDK:
API Levels: 23, 28, 29
Build Tools: 28.0.3, 29.0.1
System Images: android-26 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5791312
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
react: ^16.8.6 => 16.9.0
react-native: 0.60.5 => 0.60.5
iOS only
I am finding that when passing a 'maximumAge' of 0 into the options of getCurrentPosition() I am in-fact getting a cached results. Now I went looking into the code to see if I could see what was going on.
My configuration on the JS side looks like this:
{ timeout: 20000, maximumAge: 0 }
When I set a breakpoint in the getCurrentPosition method on the iOS side and look at the options variable you can see the maximumAge has been set to Infinity.
Now if we look at the (RNCGeolocationOptions)RNCGeolocationOptions:(id)json part of the code.
It looks as if this line: [RCTConvert NSTimeInterval:options[@"maximumAge"]] ?: INFINITY;
is converting our 0 to Infinity.
You can see this in the screenshot below:
Now according to the documentation: "If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position. If set to Infinity the device will always return a cached position regardless of its age.". So to me it looks as if we are converting our 0 to Infinity then we will be returning a cached version.
I can see this behaviour in action by adding a breakpoint to line 316 which returns our cached version. When the maximumAge is set to 0 then this line is hit, if I set it to a small number like 0.001 then the breakpoint is not hit and we carry on to make an actual geo location request.
I had a look at the history on Github and these files have not been touched in a long time so I might be barking up the wrong tree but something feels a little off.
Happy to provide more information if it helps.
when use the watchPosition() , the timeout is 500, it can't get the position and can't Invoke the error function
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.