No Description

Map.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import * as React from 'react';
  2. import { useState } from 'react';
  3. import MapView, { Marker } from 'react-native-maps';
  4. import { Button, StyleSheet, Text, View, Dimensions, Pressable } from 'react-native';
  5. export default function Map({route, navigation} ) {
  6. console.log('In map params')
  7. console.log(route.params)
  8. const {
  9. Appointment = route.params.Appointment_Date ,
  10. int_id = route.params.int_id,
  11. mapflag = route.params.Flag,
  12. i_token = route.params.I_Token,
  13. u_token = route.params.U_Token,
  14. username = route.params.Username,
  15. I_username = route.params.I_Username,
  16. View_Only = route.params.View_Only
  17. } = route.params
  18. if(View_Only == true){
  19. const Retrive_pin = route.params.Pin;
  20. console.log("Retrieve lat", Retrive_pin.Pin[0])
  21. const [pin2, setPin2] = React.useState({
  22. latitude: Retrive_pin.Pin[0],
  23. longitude: Retrive_pin.Pin[1],
  24. })
  25. console.log("Pin2", pin2)
  26. return (
  27. <View style={styles.container}>
  28. <MapView style={styles.map}
  29. initialRegion={{
  30. latitude: pin2.latitude,
  31. longitude: pin2.longitude,
  32. latitudeDelta: 0.0922,
  33. longitudeDelta: 0.0421,
  34. }}
  35. provider="google"
  36. >
  37. <Marker coordinate={pin2} />
  38. </MapView>
  39. </View>
  40. );
  41. }
  42. else{
  43. const [pin1, setPin1] = React.useState({
  44. latitude: 18.4655,
  45. longitude: -66.1057,
  46. })
  47. return (
  48. <View style={styles.container}>
  49. <MapView style={styles.map}
  50. initialRegion={{
  51. latitude: 18.4655,
  52. longitude: -66.1057,
  53. latitudeDelta: 0.0922,
  54. longitudeDelta: 0.0421,
  55. }}
  56. onPress={(e) => {
  57. setPin1({
  58. latitude: e.nativeEvent.coordinate.latitude,
  59. longitude: e.nativeEvent.coordinate.longitude
  60. })
  61. }}
  62. provider="google"
  63. >
  64. <Marker coordinate={pin1} />
  65. </MapView>
  66. <View style = {{position: 'absolute', bottom: '5%'}}>
  67. <Button title= 'Confirm Location' onPress = {() => navigation.navigate('StateTime' , {Pin : pin1 , Appointment : Appointment, int_id : int_id,
  68. mapflag : mapflag, I_Token: i_token, U_Token: u_token
  69. ,Username: username, I_Username: I_username})}/>
  70. </View>
  71. </View>
  72. );
  73. }
  74. }
  75. const styles = StyleSheet.create({
  76. container: {
  77. flex: 1,
  78. backgroundColor: '#fff',
  79. alignItems: 'center',
  80. justifyContent: 'center',
  81. },
  82. map: {
  83. width: Dimensions.get('window').width,
  84. height: Dimensions.get('window').height,
  85. },
  86. container2: {
  87. flex: 1,
  88. alignItems: 'center',
  89. justifyContent: 'center',
  90. backgroundColor: '#307ecc',
  91. padding: 16,
  92. },
  93. });