Javascript react native-expo:有没有办法在手机上打印位置;谁的屏幕?

Javascript react native-expo:有没有办法在手机上打印位置;谁的屏幕?,javascript,reactjs,react-native,expo,Javascript,Reactjs,React Native,Expo,有没有办法在我的手机屏幕上打印一些东西 当我得到位置更改时,我试图在屏幕上打印“位置” 在我的示例中,我尝试使用expo的TaskManager,因为我必须运行一些后台服务,我想在应用程序被终止时检查此方法是否有效 这是我的代码: import React from 'react'; import { Text, TouchableOpacity } from 'react-native'; import * as TaskManager from 'expo-task-manager'; im

有没有办法在我的手机屏幕上打印一些东西

当我得到位置更改时,我试图在屏幕上打印“位置”

在我的示例中,我尝试使用
expo
TaskManager
,因为我必须运行一些后台服务,我想在应用程序被终止时检查此方法是否有效

这是我的代码:

import React from 'react';
import { Text, TouchableOpacity } from 'react-native';
import * as TaskManager from 'expo-task-manager';
import * as Location from 'expo-location';

const LOCATION_TASK_NAME = 'background-location-task';

export default class Component extends React.Component {
  onPress = async () => {
    const { status } = await Location.requestPermissionsAsync();
    if (status === 'granted') {
      await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
        accuracy: Location.Accuracy.Balanced,
      });
    }
  };

  render() {
    return (
      <TouchableOpacity
      style={{alignItems: "center",paddingTop:100}}
       onPress={this.onPress}>
        <Text>Enable background location</Text>
      </TouchableOpacity>
    );
  }
}

TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => {
  if (error) {
    // Error occurred - check `error.message` for more details.
    return;
  }
  if (data) {
    const { locations } = data;

    // do something with the locations captured in the background
    // HERE I WANT TO PRINT THE "locations" INTO MY PHONE SCREEN 


  }
});
从“React”导入React;
从“react native”导入{Text,TouchableOpacity};
从“expo任务管理器”导入*作为任务管理器;
从“世博会地点”导入*作为地点;
常量位置任务名称='后台位置任务';
导出默认类组件扩展React.Component{
onPress=async()=>{
const{status}=wait Location.requestPermissionsAsync();
如果(状态==‘已授予’){
等待位置。startLocationUpdatesAsync(位置\任务\名称{
准确度:位置、准确度、平衡度,
});
}
};
render(){
返回(
启用后台位置
);
}
}
TaskManager.defineTask(位置\任务\名称,({data,error})=>{
如果(错误){
//发生错误-有关详细信息,请查看“Error.message”。
返回;
}
如果(数据){
const{locations}=数据;
//对背景中捕获的位置执行一些操作
//在这里,我想打印“位置”到我的手机屏幕
}
});