StorePosition.js
12.5 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
341
342
343
344
345
346
347
348
349
350
351
352
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 {AsyncStorage} from 'react-native'
import { Icon } from 'native-base'; // 추가된 코드
import MapView, { Marker, Polyline, LocalTile } from "react-native-maps";
import Custom_Marker from '../../assets/marker.svg'
import MapApi from "react-native-daummap";
import RNKakaoLink from 'react-native-kakao-links';
import { SERVER } from '../../common/servername';
import { getDistance, getPreciseDistance } from 'geolib';
const linkObject={
webURL :'https://developers.kakao.com/docs/android/kakaotalk-link',//optional
mobileWebURL :'https://developers.kakao.com/docs/android/kakaotalk-link',//optional
androidExecutionParams:'shopId=1&itemId=24', //optional For Linking URL
iosExecutionParams :'shopId=1&itemId=24', //optional For Linking URL
};
const contentObject = {
title : '제목',
link : linkObject,
imageURL : 'https://mud-kage.kakao.co.kr/dn/NTmhS/btqfEUdFAUf/FjKzkZsnoeE4o19klTOVI1/openlink_640x640s.jpg',
desc : '설명',//optional
imageWidth: 240,//optional
imageHeight:240//optional
}
//5개의 속성 중 최대 3개만 표시해 줍니다. 우선순위는 Like > Comment > Shared > View > Subscriber 입니다.
const socialObject ={
likeCount:12,//optional
commentCount:1,//optional
sharedCount:23,//optional
viewCount:10,//optional
subscriberCount:22//optional
}
const buttonObject = {
title:'앱으로보기',//required
link : linkObject,//required
}
const commerceDetailObject ={
regularPrice :10000,//required,
// discountPrice:1000,//Optional
// discountRate:10,//Optional
// fixedDiscountPrice:1000//Optional
};
class MainPage extends Component {
state = {
refreshing:false,
}
constructor(props) {
super(props)
this.state= {
location:null,
errorMsg:null,
current:"",
coordinate:[],
item:{},
fires:[],
state:false,
}
}
_getDistance = () => {
var dis = getDistance(
{ latitude: 20.0504188, longitude: 64.4139099 },
{ latitude: 51.528308, longitude: -0.3817765 }
);
alert(`Distance\n${dis} Meter\nor\n${dis / 1000} KM`);
};
_getPreciseDistance = () => {
var pdis = getPreciseDistance(
{ latitude: 20.0504188, longitude: 64.4139099 },
{ latitude: 51.528308, longitude: -0.3817765 }
);
alert(`Precise Distance\n${pdis} Meter\nor\n${pdis / 1000} KM`);
};
linkCustom = async () => {
try{
const options = {
objectType:'feed',//required
content:contentObject,//required
social:socialObject,//optional
buttons:[buttonObject]//optional
};
const response = await RNKakaoLink.link(options);
}catch(e){
console.warn(e);
}
}
componentDidMount() {
(async () => {
AsyncStorage.getItem("user",(err,res) => {
if(res) {
this.setState({
user:JSON.parse(res)
})
}
})
if(!this.props.navigation.state.params) {
alert("잘못된 접근입니다.")
return this.props.navigation.goBack(null)}
get(`http://${SERVER}/fire`).then(res => {
this.setState({
fires:res.data.data
})
}).catch(e => console.log(e))
get(`http://${SERVER}/stores/${this.props.navigation.state.params.item.id}`).then((res) => {
this.setState({
item:res.data.data[0]
},async () => {
let location = await Location.getCurrentPositionAsync({});
this.setState({
location
},() => {
MapApi.getCoordToAddress(location.coords.latitude,location.coords.longitude).then(res => {
this.setState({
current:res.documents[0].road_address.address_name
})
})
})
})
})
})();
}
handleNavigate = () => {
get(`https://naveropenapi.apigw.ntruss.com/map-direction/v1/driving?start=${this.state.location.coords.longitude},${this.state.location.coords.latitude}goal=${parseFloat(this.state.item.longitude)},${parseFloat(this.state.item.latitude)}&option=traoptimal`
,{headers:{'X-NCP-APIGW-API-KEY-ID':'4wo5mih29n','X-NCP-APIGW-API-KEY':'LAFshg9A5XyGTSUXWwJYiP6zX5gK7VQUr4vrUc6r'}}).then(res => {
console.log(res.data)
if(res.data && res.data.route) {
console.log(res.data.route)
res.data.route.traoptimal[0].path.map((e,i) => {
console.log(e)
this.setState((prev) => ({
coordinate: [
...prev.coordinate,
{longitude:e[0],latitude:e[1]}
]
}))
})
}
})
}
Cal_Distance = () => {
if( this.state.fires.filter((e,i) => {
if(getDistance(
{ latitude: this.state.location.coords.latitude, longitude: this.state.location.coords.longitude },
{ latitude: e.latitude, longitude: e.longitude })<500) {
return true
}
}).length > 0 && !this.state.state) {
this.setState({
state:true
})
post(`http://${SERVER}/fire_catch`,{id:this.state.user.id}).then(res => {
if(!res.data.success) {
this.setState({
state: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?<MapView
initialRegion={{
latitude: this.state.location.coords.latitude,
longitude: this.state.location.coords.longitude,
latitudeDelta: 0.005,
longitudeDelta: 0.001,
}}
maxZoom= {20}
minZoom= {1}
onRegionChange={this.Cal_Distance}
onUserLocationChange={() => this.Cal_Distance()}
style={{width:"100%",height:"84%"}} >
{this.state.coordinate.map((e,i) => {
return <Polyline
key={i}
coordinates={this.state.coordinate}
strokeColor="#FFD63A" // fallback for when `strokeColors` is not supported by the map-provider
strokeWidth={5} />
})}
{this.state.fires.map((e,i) => {
return (
<MapView.Circle
center={{
latitude:parseFloat( e.latitude),
longitude:parseFloat( e.longitude),
}}
radius={40}
fillColor={"rgba(204,117,63,0.5)"}
>
<Text style={{textAlign:"center",color:"white",fontSize:9,fontWeight:"bold"}}>
주의!
</Text>
</MapView.Circle>
)
})}
<Marker
coordinate={{
latitude: this.state.location.coords.latitude,
longitude: this.state.location.coords.longitude}}
title="내 위치"
description={`${this.state.current}`}>
<Custom_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>
<Marker
coordinate={{
latitude: this.state.item.latitude ,
longitude:this.state.item.longitude}}
title="내 위치"
description={`${this.state.current}`}>
<Custom_Marker/>
<MapView.Callout tooltip={true} style={{backgroundColor:"transparent",width:260,flexDirection:"row",paddingLeft:0}}>
<Text style={{lineHeight:25,}}>
<Image resizeMode="stretch" style={{width:78,height:50,marginTop:0,paddingTop:0,paddingLeft:0,marginLeft:0}} source={require('../../assets/img.png')}/>
</Text >
<View style={{borderWidth:2,borderColor:"#FFD63A",width:182,backgroundColor:"white",borderLeftWidth:0}}>
<View style={{marginLeft:8,justifyContent:"center",fontSize:13,color:"black"}}>
<Text>
{this.state.item.name}
</Text>
<Text style={{color:"#808083",fontSize:12}}>
{this.state.item.phone_number}
</Text>
</View>
</View>
</MapView.Callout>
</Marker>
</MapView>:<MapView></MapView>}
<View style={{flexDirection:"row",width:"100%",height:"8%",position:"absolute",justifyContent:"center",bottom:0,alignItems:"center"}}>
<TouchableOpacity onPress={() => {this.handleNavigate()}} style={{width:"50%",height:"100%",justifyContent:"center",backgroundColor:"#f4cd37"}}>
<Text style={{fontSize:17,color:"black",paddingLeft:10,textAlign:"center"}}>길찾기</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => {this.linkCustom()}} style={{width:"50%",height:"100%",justifyContent:"center",backgroundColor:"white"}}>
<Text style={{fontSize:17,color:"black",paddingLeft:10,textAlign:"center"}}>공유하기</Text>
</TouchableOpacity>
</View>
</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