1
I’m trying to make a tracker using Adian, a gps module and a gsm.
I can receive the latitude, longitude and send to cell phone as SMS, but in cell phone I’m trying to build an application with react-native
, in which I am learning, to show on the map the location.
Running tests, I got this code to monitor incoming messages:
import React, { Component } from 'react';
import {
AppRegistry,
Text,
View,
Button
} from 'react-native';
import SmsListener from 'react-native-android-sms-listener';
export default class App extends Component {
//constructor include last message
constructor(props) {
super(props);
this.state = { lastMessage: 1 };
}
sms(){
SmsListener.addListener(message => {
this.setState({ lastMessage: message.body });
});
}
render() {
return (
<View>
<Text> Scheduled jobs: {this.state.lastMessage} </Text>
<Button
title="Buscar"
color="#115E54"
onPress={() => this.sms() }
/>
</View>
);
}
}
And this code to display the map:
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
import MapView from 'react-native-maps';
export default class App extends Component {
render() {
const { region } = this.props;
console.log(region);
return (
<View style ={styles.container}>
<MapView
style={styles.map}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
}}
>
</MapView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
height: 400,
width: 400,
justifyContent: 'flex-end',
alignItems: 'center',
},
map: {
...StyleSheet.absoluteFillObject,
},
});
Both work within their functions.
The problem is in the fact that I receive the data in the SMS format 37.78825,-122.4324
and I need to break this data in two to be able to assign in latitude
and longitude
How do I do that?
Well that’s what I need, thank you
– Mateus