Coder Social home page Coder Social logo

qiuxiang / react-native-amap-geolocation Goto Github PK

View Code? Open in Web Editor NEW
384.0 7.0 97.0 818 KB

React Native geolocation module for Android + iOS

Home Page: https://qiuxiang.github.io/react-native-amap-geolocation

License: MIT License

Java 20.39% JavaScript 11.95% Ruby 1.52% Objective-C 11.88% TypeScript 54.26%
react-native amap location geolocation

react-native-amap-geolocation's Introduction

react-native-amap-geolocation

注意:该项目目前只维护,不加新功能。

React Native 高德地图定位模块,支持 Android + iOS,提供尽可能完善的原生接口, 同时提供符合 Web 标准的 Geolocation API。

用法

import { PermissionsAndroid } from "react-native";
import { init, Geolocation } from "react-native-amap-geolocation";

await PermissionsAndroid.requestMultiple([
  PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
  PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
]);

await init({
  ios: "9bd6c82e77583020a73ef1af59d0c759",
  android: "043b24fe18785f33c491705ffe5b6935",
});

Geolocation.getCurrentPosition(({ coords }) => {
  console.log(coords);
});

文档

react-native-amap-geolocation's People

Contributors

clumsyme avatar dfenglei avatar qiuxiang avatar symous avatar wuxushun avatar ych1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-amap-geolocation's Issues

IOS有闪退的机率

场景描述如下:
有客户反馈使用了APP某个定位功能,APP有很大的机率闪退。我叫他关闭了定位权限,再次使用这个功能。这个时候APP不会闪退。
我推测导致闪退的原因,是不是由于客户地区信号较差,导致定位很慢,乃至地理逆编码失败。
正常情况下,我没遇到闪退情况。

显示evaluating 'v.GeoLocation.init'

测试代码如下:
import { GeoLocation } from "react-native-amap-geolocation";
export default class Example extends Component {
componentWillMount() {
GeoLocation.init({
// ios: "",
android: "ef095fa431becc2c63e225deb8c14f87"
})
}

async componentDidMount() {
    Geolocation.setOptions({
        interval: 10000,
        distanceFilter: 10,
        reGeocode: true
    });
    Geolocation.addLocationListener(location => {
        console.log(location)
    })
}

componentWillUnmount() {
    Geolocation.stop()
}

render() {
    const {location} = this.state
    return (
        <View style={style.body}>
            <View style={style.controls}>
                <Button
                    type = 'primary'
                    style={style.button}
                    onPress={() => Geolocation.start()}
                    title="开始定位"
                />
                <Button
                     type = 'primary'
                    style={style.button}
                    onPress={() => Geolocation.stop()}
                    title="停止定位"
                />
            </View>
        </View>
    )
}

}

调试控制台显示错误
E/ReactNativeJS: TypeError: undefined is not an object (evaluating 'v.GeoLocation.init')
不知道如何解决这个问题

安卓初次定位返回结果慢

非常感谢作者的付出,但是我在使用过程中发现安卓手机在运行app后,初次请求定位返回需要等待很久的时候,后续就是按照间隔时间来返回的了。
想请教作者,初次定位慢是不是因为有做限制初次定位必须是仅gps结果,而没有采用传统的高精度或者低功耗模式得到的结果,后续结果变快则是允许了可以使用非gps结果返回。
是不是可以在配置时提供一个选项来决定使用什么模式获取定位呢?

希望能有IOS能通过link 实现

希望能有IOS能通过link 实现, 因为很多没做过ios的对pod不会用,并且pod出现的问题也不知道如何解决。如果能直接link关联使用

Android permission problem

The existence of Android permission problem

my Android bulid
` compileSdkVersion 27
buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.zhgdsystem"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "0.0.1"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
    multiDexEnabled true
}`

so i do this in ‘init’ checkSelfPermission
int permission = ActivityCompat.checkSelfPermission(reactContext, Manifest.permission.WRITE_EXTERNAL_STORAGE); int permissionL = ActivityCompat.checkSelfPermission(reactContext, Manifest.permission.ACCESS_COARSE_LOCATION); if (permission != PackageManager.PERMISSION_GRANTED || permissionL != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user ActivityCompat.requestPermissions(reactContext.getCurrentActivity(), PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE); }

如何获取移动方向 direction?

文档中没有介绍,我在使用是经纬度,速度,位置等信息都能获取,但没有获取到设备的移动方向direction。请问要如何解决?

逆地址编码不成功

ios 项目 ,
定位信息中没有逆地理编码,但是当我调用过 react-Native-amap3D 地图之后,再去定位,就都有城市信息就都有了

Geolocation.init()后,在componentWillUnmount时需不要注销

环境:

window10

react-native 0.57

Android 8.0

需求:

想实现进入页面获取一次(只想要一次)定位信息,当重新进入这个页面的时候,获取新的定位信息

目前的测试代码

    componentDidMount () {
        this._getLocation()
    };
    componentWillUnmount () {
    }
    async _getLocation () {
        await Geolocation.init({
            android: "0177d4e25ce33b889e1a5608a0cf682f"
        })

        Geolocation.setOptions({
            // interval: 8000,
            // distanceFilter: 20
            setOnceLocation: true
        })

        Geolocation.addLocationListener(location => {
            console.log(location, 'location data')
            Geolocation.stop()
        })
        Geolocation.start()
    }

遇到的问题:

第一次进入页面console会打印一条信息,第二次进入会打印两条信息,第N次进入会打印N条信息。

期望:

不管哪次进入页面都想值获取一条信息

疑问:

是否需要在componentWillUnmount()中注销Geolocation, 再次进入页面时重新init() , 有注销Geolocation的方法吗?

android8.0 定位没有询问是否开启位置权限

android8.0
node v10.13.0
npm v6.4.1
react-native-cli v2.0.1
react-native v0.57.8

默认没有弹窗询问权限,要手动在设置里修改位置权限为允许才能有回调,这个要怎么处理,有小伙伴遇到吗

在比较偏僻的地方定位会导致闪退,提示"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[8]'"

环境:
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-amap-geolocation": "^0.3.2",

开发工具:Mac

定位的经纬度:lat: 38.6511983323, long: 82.3974609375

错误提示:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[8]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108b921bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000109cab735 objc_exception_throw + 48
2 CoreFoundation 0x0000000108ade4ec _CFThrowFormattedException + 194
3 CoreFoundation 0x0000000108c01541 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 321
4 CoreFoundation 0x0000000108b8dc9b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
5 yidaoClient 0x000000010466be4f -[RCTLocationModule json:reGeocode:] + 1839
6 yidaoClient 0x000000010466c4b1 -[RCTLocationModule amapLocationManager:didUpdateLocation:reGeocode:] + 129
7 yidaoClient 0x00000001046c9f34 __72-[AMapLocationManager notifySerialLocateDelegateWithLocation:reGeocode:]_block_invoke + 93
8 libdispatch.dylib 0x000000010bf64595 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x000000010bf65602 _dispatch_client_callout + 8
10 libdispatch.dylib 0x000000010bf7299a _dispatch_main_queue_callback_4CF + 1541
11 CoreFoundation 0x0000000108af73e9 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
12 CoreFoundation 0x0000000108af1a76 __CFRunLoopRun + 2342
13 CoreFoundation 0x0000000108af0e11 CFRunLoopRunSpecific + 625
14 GraphicsServices 0x000000010f62c1dd GSEventRunModal + 62
15 UIKitCore 0x00000001139a781d UIApplicationMain + 140
16 yidaoClient 0x00000001043f6d00 main + 112
17 libdyld.dylib 0x000000010bfdb575 start + 1
18 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

为什么会回调多次

发现Geolocation.addLocationListener(location => {
console.log(location);
}

会回调多次

能只调用一次吗

后台定位

大佬 我看来高德地图api后在您的代码里加了几句允许后台定位的话
然后使用的时候报这个错
Sending AMapGeolocation with no listeners registered.
我不知道该怎么添加listener了 需要帮助

import { Geolocation } from "react-native-amap-geolocation" 报错

大牛好,现在遇到问题如下:

  1. npm install react-native-amap-geolocation
    2.react-native link
    3.在页面 import { Geolocation } from "react-native-amap-geolocation"
    错误提示 ‘react-native-amap-geolocation’ does not exist
    在react-native-amap-geolocation 库中 android目录下并未发现index.js 或index.ts 文件的存在, 是否忘记暴露模块了。

MainApplication.java:6: 错误: 程序包cn.qiuxiang.react.geolocation不存在, 请问这里应该怎么处理

E:\LianjiangProject\GongJiang\android\app\src\main\java\com\gongjiang\MainApplication.java:6: 错误: 程序包cn.qiuxiang.react.geolocation不存在
import cn.qiuxiang.react.geolocation.AMapGeolocationPackage;
^
E:\LianjiangProject\GongJiang\android\app\src\main\java\com\gongjiang\MainApplication.java:28: 错误: 找不到符号
new AMapGeolocationPackage(),
^
符号: 类 AMapGeolocationPackage
2 个错误
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 31.141 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

ios pod install error ,如何解决?

Analyzing dependencies
Fetching podspec for React from ../node_modules/react-native
Fetching podspec for react-native-amap-geolocation from ../node_modules/react-native-amap-geolocation/lib/ios
Fetching podspec for yoga from ../node_modules/react-native/ReactCommon/yoga
Downloading dependencies
Installing AMapFoundation (1.5.3)
Installing AMapLocation (2.6.0)
Using DoubleConversion (1.1.5)
Using Folly (2016.10.31.00)
Installing React 0.56.0
Using boost-for-react-native (1.63.0)
Using glog (0.3.4)
Installing react-native-amap-geolocation (0.3.1)
Using yoga (0.56.0.React)
重点错误地方:[!] The 'Pods-ddh' target has transitive dependencies that include static binaries: (/Users/sea/Desktop/ddh/ios/Pods/AMapLocation/AMapLocationKit.framework)

页面引用:import {GeoLocation} from 'react-native-amap-geolocation';//编译提示geolocation.js
const eventEmitter = new NativeEventEmitter(AMapGeolocation)
NativeEventEmitter can not be null

ios 编译报错

大牛好:
iOS 按照你的安装文档进行安装后,编译报下面的错,iOS小白一枚,能否指点一下?
另位您的Podfile 中有一处错误(我的react 版本 0.50.0 最新的没有验证)
应为 pod 'GLog', :podspec => '../node_modules/react-native/third-party-podspecs/GLog.podspec'吧,谢谢!!

ld: warning: directory not found for option '-L/Users/wang/Library/Developer/Xcode/DerivedData/IBCSSSMOBILE-ctehwpmuzypsbtccxtylhmrcolsj/Build/Products/Debug-iphonesimulator/DoubleConversion'
ld: warning: directory not found for option '-L/Users/wang/Library/Developer/Xcode/DerivedData/IBCSSSMOBILE-ctehwpmuzypsbtccxtylhmrcolsj/Build/Products/Debug-iphonesimulator/Folly'
ld: warning: directory not found for option '-L/Users/wang/Library/Developer/Xcode/DerivedData/IBCSSSMOBILE-ctehwpmuzypsbtccxtylhmrcolsj/Build/Products/Debug-iphonesimulator/GLog'
ld: warning: directory not found for option '-L/Users/wang/Library/Developer/Xcode/DerivedData/IBCSSSMOBILE-ctehwpmuzypsbtccxtylhmrcolsj/Build/Products/Debug-iphonesimulator/React'
ld: warning: directory not found for option '-L/Users/wang/Library/Developer/Xcode/DerivedData/IBCSSSMOBILE-ctehwpmuzypsbtccxtylhmrcolsj/Build/Products/Debug-iphonesimulator/react-native-amap-geolocation'
ld: warning: directory not found for option '-L/Users/wang/Library/Developer/Xcode/DerivedData/IBCSSSMOBILE-ctehwpmuzypsbtccxtylhmrcolsj/Build/Products/Debug-iphonesimulator/yoga'
ld: library not found for -lDoubleConversion
clang: error: linker command failed with exit code 1 (use -v to see invocation)

逆地理编码的问题

发现使用自带的demo,在刷新两三次之后,是能够获取到所给坐标对应的地址的,但是将demo的代码放到我们自己的app内,就无法获取到地址。Key也是换为了我们自己的key了。请问这可能是哪块的配置有问题?

希望有单次定位返回Promise的api

hi,感谢作者封装了高德SDK方便RN开发者!
业务中需要单次定位返回结果,同一个界面可能有多处使用,目前的方式,listener中无法明确知道是哪个业务的数据接着执行什么,而且多个page都有监听的话,多个listener应该都会有数据,所以感觉还是有一个单次定位返回Promise的api使用起来会比较方便,刚接触RN,希望描述能看懂

配置了 (android/app/build.gradle)定位没反应

用了一个组件react-native-image-crop-picker,需要配置如下,但是这样定位就没反应了,请问一下能有方法解决吗
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
...

defaultConfig {
  ...
  targetSdkVersion 27
  ...
}
...

}

在Android手机上有时候会出现getTime() on a null object

感谢作者为RN 生态提供地位插件。
由于本人在开发的时候用了两台手机,一台Android7,一台Android5,
在Android7中用该定位有时候会出现如下问题,但是同样的代码在Android5中没有这个问题。
请问这种改怎么处理
image

没有监听到定位返回的数据

我把你这个项目的index.js copy到我的项目文件中执行,调用了开始定位方法,却没有任何定位信息返回,console里面也没有。

image

开发环境:
Android 8.0.0
"react": "16.4.1",
"react-native": "0.55.4",
"react-native-amap-geolocation": "^0.3.1"

android7中出现 getLastKnownLocation() on a null object

开发环境:
RN : 0.53.3
测试环境
Android5(魅族) & Android7(华为荣耀6x)

作者你好,在使用该库中发现了两个问题,已下问题均出现在Android7 中,Android5 尚未发现问题,一切正常。
问题1:

Attempt to invoke virtual method ' com.amap.api.location.AMapLocation com.amap.api.location.AMapLocationClient.getLastKonwnLocation()  on a null object reference'

screenshot_20180627-161550

问题2:
在使用定位当中,获取的数据里面只有经纬度,没有具体的详细地址。
最后感谢作者提供的定位库

getLastLocation无法获取返回数据

`import React from "react";
import { AppRegistry, Button, StyleSheet, Text, View } from "react-native";
import { Geolocation } from "react-native-amap-geolocation";

const style = StyleSheet.create({
body: {
padding: 16
},
controls: {
flexDirection: "row",
justifyContent: "space-around",
marginTop: 12,
marginBottom: 24
},
item: {
flexDirection: "row",
marginBottom: 4
},
label: {
color: "#f5533d",
width: 120,
paddingRight: 10,
textAlign: "right"
}
});

class App extends React.Component {
state = { location: {} };

async componentDidMount() {
await Geolocation.init({
ios: "9bd6c82e77583020a73ef1af59d0c759",
android: "043b24fe18785f33c491705ffe5b6935"
});
Geolocation.setOptions({
interval: 10000,
distanceFilter: 10,
background: true,
reGeocode: true
});
Geolocation.addLocationListener(location =>
this.updateLocationState(location)
);
}

componentWillUnmount() {
Geolocation.stop();
}

updateLocationState(location) {
if (location) {
location.timestamp = new Date(location.timestamp).toLocaleString();
this.setState({ location });
console.log(location);
}
}

startLocation = () => Geolocation.start();
stopLocation = () => Geolocation.stop();
getLastLocation = async () =>
this.updateLocationState(await Geolocation.getLastLocation());

render() {
const { location } = this.state;
return (





{Object.keys(location).map(key => (

{key}
{location[key]}

))}

);
}
}

AppRegistry.registerComponent("RNAMapGeolocation", () => App);
`
手动调用getLastLocation()方法,无法获取返回信息

[建议] pod install 之后的duplicate错误,不能archive等问题的修复方案

运行环境

macOS High Sierra 10.13.6

  • 插件版本: 2.2.7
  • react-native 版本:0.55.4

期望效果

应用能在debug和release环境中运行并且能archive

实际效果

若debug环境运行成功则不能release,反之亦然。不能archive

重现步骤

原有的RN项目中按照此插件readme集成

Debug logs

各种duplicate error, linker error

修复方案:跟随下面链接里的最火答案,祝你们愉快(答案里的图片很重要)
facebook/react-native#15838

ios无法获取城市信息

如题,以正确配置key,安卓可以获取定位到的城市信息,ios获取不到,只有经纬度信息

addLocationListener 这个方法在初始化之后 很久才监听成功

rn版本: ^0.57.4

在componentDidMount 中做了初始化。想通过addLocationListener 这个方法来获取,一开始的经纬度信息,然后放入高德地图的coordinate中,但是发现 这个方法 在页面打开之后 过了很久才返回了 经纬度信息。
这是什么原因哇。但是在模拟器上面都秒出现。真机 就变得很慢

因为后台持续定位问题,苹果审核无法通过

使用了background: number这个属性之后,在模拟器上可以在后台定位,获取信息,但是提交商城时一直说我的app使用了后台持续定位的权限,但是在APP中没有用到,总是无法过审,我把background去掉之后,删除定位权限已经通过审核了。求解怎么解决啊?项目需要这个功能啊

调用init报错:TypeError: undefined is not an object (evaluating 'AMapGeolocation.init')

项目基于GeekyAnts的react-native-boilerplate-mobx-flow,修改过package.json,部分package.json如下所示。

...
"dependencies": {
"expo": "^30.0.0",
"lodash": "4.17.4",
"mobx": "3.4.1",
"mobx-react": "4.3.5",
"native-base": "2.6.1",
"query-string": "^6.0.0",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz",
"react-native-amap-geolocation": "^0.3.2",
"react-native-datepicker": "^1.7.2",
"react-navigation": "^2.13.0"
}
...

项目使用npm i react-native-amap-geolocation安装后,重新npm install,运行时控制台报错[TypeError: undefined is not an object (evaluating 'AMapGeolocation.init')]。部分代码如下所示。

...
import { Geolocation } from "react-native-amap-geolocation"
...
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
Toast.show({
text: "请打开位置信息",
duration: 1500,
position: "top",
textStyle: { textAlign: "center" },
type: 'danger'
});
}
await Geolocation.init({
ios: iosKey,
android: androidKey,
});

请问该如何解决?
如需更多信息,请指出。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.