No Description

Map.js 2.6KB

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