GoogleMap_Like.js
13.4 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import React,{ Component } from 'react'
import {View,Text,RefreshControl,Image,ScrollView,Dimensions,TextInput,TouchableOpacity,StatusBar,StyleSheet} from 'react-native'
import { post, get, put, delete as remove } from 'axios'
import * as Location from 'expo-location';
import { Icon } from 'native-base'; // 추가된 코드
import MapView, { Marker, Polyline } from "react-native-maps";
import Fake_Marker from '../../assets/marker.svg'
import MapApi from "react-native-daummap";
import AsyncStorage from '@react-native-community/async-storage'
import Modal from 'react-native-modal'
import Search from '../../assets/search.svg'
class MainPage extends Component {
state = {
refreshing:false,
}
constructor(props) {
super(props)
this.state= {
location:null,
errorMsg:null,
latitude:0,
longitude:0,
current:"",
isModalVisible:false,
detail:"",
road_address:"",
address:"",
search:"",
isSearching:false,
searchLatitude:0,
searchLongitude:0,
}
}
componentDidMount() {
if(this.props.navigation.state.params && this.props.navigation.state.params.item) {
this.setState({
latitude:this.props.navigation.state.params.item.lat,
longitude:this.props.navigation.state.params.item.lng
})
}
if(this.props.navigation.state.params && this.props.navigation.state.params.address) {
MapApi.serachAddress(this.props.navigation.state.params.address,1,1).then(res => {
this.setState({
location:{
coords: {
latitude: parseFloat(res.documents[0].y),
longitude:parseFloat(res.documents[0].x)
}
},
latitude:parseFloat(res.documents[0].y),
longitude:parseFloat(res.documents[0].x)
})
})
}
else {
(async () => {
let location = await Location.getCurrentPositionAsync({});
MapApi.getCoordToAddress(location.coords.latitude,location.coords.longitude).then(res => {
if(res.documents[0].road_address) {
var temp = res.documents[0].road_address.address_name + " (" + res.documents[0].address.region_3depth_name + " " +res.documents[0].address.main_address_no
res.documents[0].address.sub_address_no? temp+=("-" +res.documents[0].address.sub_address_no):undefined
temp+=")"
}
else {
var temp = res.documents[0].address.address_name
}
this.setState({
current:temp,
road_address:res.documents[0].road_address.address_name,
address:res.documents[0].address.address_name
})
})
this.setState({
location,
latitude:location.coords.latitude,
longitude:location.coords.longitude
},() => {
})
})();
}
}
getCurrentPosition = () => {
MapApi.getCoordToAddress(this.state.latitude,this.state.longitude).then(res => {
if(res.documents[0].road_address) {
var temp = res.documents[0].road_address.address_name + " (" + res.documents[0].address.region_3depth_name + " " +res.documents[0].address.main_address_no
res.documents[0].address.sub_address_no? temp+=("-" +res.documents[0].address.sub_address_no):undefined
temp+=")"
}
else {
var temp = res.documents[0].address.address_name
}
this.setState({
current:temp,
address:res.documents[0].address.address_name,
road_address:res.documents[0].road_address? res.documents[0].road_address.address_name:""
})
})
}
savePosition = () => {
if(!this.state.detail) return alert("모든 항목을 입력해주세요.")
AsyncStorage.getItem("LikeAddress",(err,res) => {
if(!res) {
AsyncStorage.setItem("LikeAddress",JSON.stringify([{lat:this.state.latitude,lng:this.state.longitude,address:this.state.address,road_address:this.state.road_address,current:this.state.current,date:new Date(),name:this.state.detail}]))
}
else {
if(this.props.navigation.state.params && this.props.navigation.state.params.item) {
const temp = JSON.parse(res)
temp[this.props.navigation.state.params.index] = {lat:this.state.latitude,lng:this.state.longitude,address:this.state.address,road_address:this.state.road_address,current:this.state.current,date:new Date(),name:this.state.detail}
AsyncStorage.setItem("LikeAddress",JSON.stringify(temp))
}
else {
const temp = JSON.parse(res)
AsyncStorage.setItem("LikeAddress",JSON.stringify(temp.concat([{lat:this.state.latitude,lng:this.state.longitude,address:this.state.address,road_address:this.state.road_address,current:this.state.current,date:new Date(),name:this.state.detail}])))
}
}
})
this.setState({
isModalVisible:false
})
this.props.navigation.navigate('Main_')
}
searchAddress = (e) => {
if(e.nativeEvent.target) {
MapApi.serachAddress(this.state.search).then(res => {
this.setState({
isSearching:true
},() => {
this.setState({
searchLongitude:parseFloat(res.documents[0].x),
searchLatitude:parseFloat(res.documents[0].y),
longitude:parseFloat(res.documents[0].x),
latitude:parseFloat(res.documents[0].y),
search:res.documents[0].address.address_name,
},() => {
this.setState({
isSearching:false
})
})
})
})
}
}
render() {
return (
<View style={{height:"100%",width:"100%",backgroundColor:"transparent"}}>
<View style={{display:"flex",flexDirection:"row", height:"8%",backgroundColor:"#5f6161",alignItems:"center"}}>
<Icon name="ios-arrow-back" style={{color:"#f4cd37", paddingLeft:10}}/>
<Text style={{fontSize:17,color:"white",paddingLeft:10}}>위치 설정</Text>
</View>
{this.state.location || this.state.latitude?
<View style={{width:"100%",height:"84%"}}>
<View style={{alignSelf:"center",marginBottom:10,position:"absolute",top:"35%",zIndex:100,paddingLeft:16,paddingTop:5,paddingBottom:5,borderWidth:1,borderColor:"#615F5F",width:260,backgroundColor:"white"}}>
<Text style={{fontWeight:"bold",textAlign:"left"}}>
내 위치
</Text>
<Text>
{this.state.current}
</Text>
</View>
<View style={{height:40}}>
<View style={{justifyContent:"center",position:"absolute"}}>
<Search width={18} height={18} style={{marginTop:10,marginLeft:10,zIndex:5}}/>
</View>
<TextInput value={this.state.search} onChangeText={e => this.setState({search:e})} onSubmitEditing={(e) => this.searchAddress(e)} style={{height:"100%",backgroundColor:"white",width:"100%",paddingLeft:40, fontSize:13}} placeholder="주소로 검색"/>
</View>
<MapView
initialRegion={{
latitude: this.state.latitude,
longitude: this.state.longitude,
latitudeDelta: 0.005,
longitudeDelta: 0.001,
}}
region={this.state.isSearching?{
latitude: this.state.searchLatitude,
longitude: this.state.searchLongitude,
latitudeDelta: 0.005,
longitudeDelta: 0.001, }:undefined}
minZoom= {20}
trac
onRegionChange={(region) => {
this.setState({
latitude:region.latitude,
longitude:region.longitude
})
}}
onRegionChangeComplete={(region) => {
this.getCurrentPosition()
}}
showsUserLocation={true}
style={{width:"100%",height:"100%"}} >
<Marker style={{display:"none"}} coordinate={{
latitude: this.state.latitude,
longitude: this.state.longitude}}
title="내 위치"
description={this.state.current}>
<Fake_Marker/>
<MapView.Callout
style={{alignItems:"center",width:260}}>
<View style={{width:"100%"}}>
<Text style={{fontWeight:"bold"}}>
이 위치에서 검색
</Text>
<Text>
{`${this.state.current}`}
</Text>
</View>
</MapView.Callout>
</Marker>
</MapView>
</View>:<MapView></MapView>}
<TouchableOpacity onPress={() => {
this.setState({isModalVisible:true})
}} style={{width:"100%",height:"8%",position:"absolute",justifyContent:"center",bottom:0,backgroundColor:"#f4cd37",alignItems:"center"}}>
<Text style={{fontSize:17,color:"white",paddingLeft:10,}}>즐겨찾기 추가</Text>
</TouchableOpacity>
<Modal onBackButtonPress={() => this.setState({isModalVisible:false})} onBackdropPress={() => this.setState({isModalVisible:false})} isVisible={this.state.isModalVisible}>
<View style={{ width:"100%",backgroundColor:"white",alignSelf:"center",paddingTop:16,paddingLeft:16,paddingRight:16}}>
<Text style={{fontSize:17,fontWeight:"bold",marginBottom:16}}>
즐겨찾기 추가&편집
</Text>
<View style={{flexDirection:"row",marginBottom:18}}>
<Text style={{fontSize:15,color:"#615F5F"}}>
{this.state.current}
</Text>
</View>
<TextInput value={this.state.detail} onChangeText={e => this.setState({detail:e})} placeholder="ex) 집" style={{width:"100%",paddingLeft:16,marginBottom:16,alignSelf:"center",borderColor:"#FFD63A",borderWidth:1}}>
</TextInput>
</View>
<View style={{flexDirection:"row"}}>
<TouchableOpacity onPress={() => this.savePosition()} style={{width:"50%",paddingTop:12,paddingBottom:15,backgroundColor:"#FFD63A"}}>
<Text style={{fontWeight:"bold",fontSize:14,textAlign:"center"}}>
추가
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({isModalVisible:false})} style={{width:"50%",paddingTop:12,paddingBottom:15,backgroundColor:"white"}}>
<Text style={{fontWeight:"bold",fontSize:14,textAlign:"center"}}>
취소
</Text>
</TouchableOpacity>
</View>
</Modal>
</View>
)
}
}
const style=StyleSheet.create({
list_pick_event: {
paddingTop:17,
paddingBottom:17,
borderBottomColor:"#BBB9B9",
borderTopColor:"#BBB9B9",
borderBottomWidth:0.5,
},
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
avatar : {
width:32,
height:32,
borderRadius:100,
},
detail: {
marginLeft:15,
flex:1,
flexDirection:"row",
},
hit: {
fontSize:9,
fontWeight:"bold"
},
date: {
marginLeft:9,
fontSize:9,
color:"black"
},
userWrapper : {
flex:1,
flexDirection:"row",
paddingTop:13,
paddingBottom:17,
borderBottomColor:"#AEAEAE",
borderBottomWidth:1,
},
nickname : {
marginLeft:10,
fontSize:13,
fontWeight:"bold",
color:"black"
},
title : {
fontSize:13,
fontWeight:"bold",
color:"black"
},
like : {
marginTop:3,
fontSize:10,
color:"red",
marginLeft:5,
},
titleWrapper : {
marginTop:17,
paddingLeft:19,
flex:1,
flexDirection:"row"
}
})
export default MainPage