Skip to content

Instantly share code, notes, and snippets.

@voidnerd
Created February 19, 2020 10:23
Show Gist options
  • Save voidnerd/2bde4fd9728aa4d09fe11f7920d5d2b9 to your computer and use it in GitHub Desktop.
Save voidnerd/2bde4fd9728aa4d09fe11f7920d5d2b9 to your computer and use it in GitHub Desktop.
import React from "react";
import MapView from "react-native-maps";
import {
StyleSheet,
Image,
TouchableOpacity,
View,
Dimensions
} from "react-native";
import {
Container,
Header,
Content,
Left,
Body,
Right,
Button,
Icon,
Title
} from "native-base";
import * as Location1 from "expo-location";
import Head from "../components/Head";
export default class Location extends React.Component {
state = {
region: {
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0222,
longitudeDelta: 0.0021
}
};
async componentDidMount() {
let location = await Location1.getCurrentPositionAsync({});
let region = {
...this.state.region,
latitude: location.coords.latitude,
longitude: location.coords.longitude
};
this.setState({ region });
}
render() {
return (
<Container style={{ backgroundColor: "#4C3760" }}>
<Head title="My Location" navigation={this.props.navigation} />
<Content padder contentContainerStyle={styles.container}>
<MapView region={this.state.region} style={styles.mapStyle}>
<MapView.Circle
center={{
latitude: this.state.region.latitude,
longitude: this.state.region.longitude
}}
radius={100}
strokeWidth={2}
strokeColor="rgba(128,191,255, 0.3)"
fillColor="rgba(128,191,255, 0.3)"
/>
<MapView.Marker
coordinate={{
latitude: this.state.region.latitude,
longitude: this.state.region.longitude
}}
/>
</MapView>
<TouchableOpacity style={styles.panic}>
<Image
style={styles.img}
source={require("../assets/panic_button.png")}
/>
</TouchableOpacity>
</Content>
</Container>
// <View style={styles.container}>
// <MapView style={styles.mapStyle} />
// </View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
},
mapStyle: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").height
},
panic: {
// marginTop: 20,
// marginLeft: 25,
borderRadius: 100,
position: "absolute",
bottom: -10,
// alignSelf: 'flex-start',
alignSelf: "center",
// backgroundColor: '#4C3760',
// width: Dimensions.get('window').width - 40,
padding: 5,
marginBottom: 10
},
img: {
borderRadius: 100,
height: 60,
width: 60
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment