首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取使用react的卫星数量

获取使用react的卫星数量
EN

Stack Overflow用户
提问于 2018-02-17 08:14:10
回答 2查看 1.1K关注 0票数 0

我正在使用反应本土化创建我的安卓应用程序。我安装了反应-本机融合定位以获得更好的位置。我想知道我的全球导航卫星系统传感器能找到多少颗卫星,知道有多少颗卫星已经修好了。我知道我的全球导航卫星系统传感器可以传输NMEA格式,但我不知道该如何获得NMEA文件。我的GNSS传感器已经通过蓝牙连接到我的android手机上。全球导航卫星系统的传感器是高目标Qbox系列地理信息系统数据采集器。谢谢。

更新:

我发现可以通过NMEA格式获得卫星数量。

这是GGA的答复:

08,0.9,545.4,M,46.9,M,M,*47

我可以找到08颗卫星正在被跟踪。

所以,我只需要得到NMEA字符串。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-12 07:24:35

这个问题通过创建一个本机模块来解决。

我在下面的目录中创建了两个文件来支持我的项目的“卫星数量”。

代码语言:javascript
复制
C:\Users\user\Desktop\project_name\android\app\src\main\java\com\project_name

AnExampleReactPackage.java

代码语言:javascript
复制
package com.facebook.react.modules.toast;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class AnExampleReactPackage implements ReactPackage {

  @Override
  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
    return Collections.emptyList();
  }

  @Override
  public List<NativeModule> createNativeModules(
                              ReactApplicationContext reactContext) {
    List<NativeModule> modules = new ArrayList<>();

    modules.add(new ToastModule1(reactContext));

    return modules;
  }

}

ToastModule1.java

代码语言:javascript
复制
package com.facebook.react.modules.toast;

import android.widget.Toast;

import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.content.Context;
import com.facebook.react.bridge.ReadableMap;
import android.os.Bundle;


import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;



public class ToastModule1 extends ReactContextBaseJavaModule {

  ReactApplicationContext mReactContext;
  private LocationManager locationManager;

  public ToastModule1(ReactApplicationContext reactContext) {
    super(reactContext);
    ReactApplicationContext mReactContext = reactContext;
    locationManager = (LocationManager) mReactContext.getSystemService(Context.LOCATION_SERVICE);
    }

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

  @ReactMethod
  public void show(String message, int duration) {
    Toast.makeText(getReactApplicationContext(), message, Toast.LENGTH_SHORT).show();
  }

  @ReactMethod
  public void getCoors(){
      // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {

    public void onLocationChanged(Location location) {
        // Called when a new location is found by the network location provider.
            show("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()+", Satellites:" +location.getExtras().getInt("satellites"),1);
        }

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}

    };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

  }

 }

之后,我在我的MainApplication.java文件中添加了这一行:

代码语言:javascript
复制
...
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new AnExampleReactPackage() // <-- Add this line with your package name.
      );
    }
...

最后,我在App.js文件中添加了以下代码,以使用本机模块App.js或android.index.js

代码语言:javascript
复制
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View
} from 'react-native';
import {NativeModules} from 'react-native';



function findNumberOfSatellites(context){
    NativeModules.ToastExample.show("It's Starting to find satellites!", 1);
    var count = "searching...";
    NativeModules.ToastExample.getCoors();
    context.setState({satellites : count});

    }




export default class App extends Component<Props> {
    constructor(props) {
    super(props);
    this.state = {satellites: null}
    }
  componentDidMount(){
      setTimeout(findNumberOfSatellites,500,this);
  }
  render() {

    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
            Satellite Counter!
        </Text>
        <Text style={styles.instructions}>
            {this.state.satellites}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  }
});
票数 0
EN

Stack Overflow用户

发布于 2018-12-07 15:32:35

我编写了一个使用NmeaLocationListener获取NMEA语句的react本机库。https://github.com/ivanstan/react-native-nmea-library

它只在Android上工作,因为IOS不公开NMEA信息。此外,这是高度硬件依赖,所以没有保证它将在每一个手机上工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48839312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档