小编por*_*rsa的帖子

React-native Android地理定位

我需要在React-native Android上检测用户的地理位置,但是当前的实现仅支持iOS.我没有在任何地方找到任何教程或相关问题.

我试图为此创建自己的Android原生组件.我已经尝试使用模拟器(通过命令行设置一些坐标)和手机,但操作栏中没有gps图标,并且反应回调中没有数据.

我正在尝试立即获取最后一个已知位置,我也正在设置事件监听器以进行更新.

public class GeoLocation extends ReactContextBaseJavaModule implements
    GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

protected static final String TAG = "GeoLocation";
protected GoogleApiClient mGoogleApiClient;
protected Location mLastLocation;


public GeoLocation(ReactApplicationContext reactContext) {
    super(reactContext);
    buildGoogleApiClient();
}

@Override
public String getName() {
    return "GeoLocation";
}

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(getReactApplicationContext())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
    mGoogleApiClient.connect();
}

@Override
public void onConnected(Bundle connectionHint) {

    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    //WritableMap params = Arguments.createMap();

    //Can I use ConcurrentHashMap instead of WritableMap?
    ConcurrentHashMap<String, String> params = …
Run Code Online (Sandbox Code Playgroud)

android geolocation react-native

4
推荐指数
1
解决办法
5672
查看次数

标签 统计

android ×1

geolocation ×1

react-native ×1