-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaps.js
105 lines (83 loc) · 2.23 KB
/
maps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React, { Component } from "react";
import { StyleSheet, Dimensions, View, Text, AppRegistry, ActivityIndicator, ToastAndroid } from "react-native";
import MapView from 'react-native-maps';
const { width, height } = Dimensions.get('window');
export default class App extends Component {
constructor() {
super()
this.state = {
region: {
latitude: null,
longitude: null,
latitudeDelta: null,
longitudeDelta: null,
}
}
}
calcDelta(lat, lon, accuracy) {
const oneDegreeOfLongitudInMeters = 111.32;
const circumferance = (40075 / 360)
const latDelta = accuracy * (1 / (Math.cos(lat) * circumferance))
const lonDelta = (accuracy / oneDegreeOfLongitudInMeters)
this.setState({
region: {
latitude: lat,
longitude: lon,
latitudeDelta: latDelta,
longitudeDelta: lonDelta,
}
}, () => console.log(this.state.region))
}
componentWillMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
const lat = position.coords.latitude
const lon = position.coords.longitude
const accuracy = position.coords.accuracy
this.calcDelta(lat, lon, accuracy)
},
(error) => { ToastAndroid.show(error.message, ToastAndroid.SHORT) },
{ enableHighAccuracy: true, },
);
}
marker() {
return {
latitude: this.state.region.latitude,
longitude: this.state.region.longitude
}
}
render() {
console.log(this.state.region.latitude);
if (this.state.region.latitude == null) {
return <View style={styles.container}>
<ActivityIndicator size="large" color="#0000ff" />
</View>
}
return (
<View style={styles.container}>
<MapView
style={styles.map}
initialRegion={this.state.region}
>
<MapView.Marker
coordinate={this.marker()}
title="You are Here"
description="Your Location"
/>
</MapView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2980b9'
},
map: {
flex: 1,
width: width,
}
});