Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7912 | Rev 7935 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 7912 Rev 7917
Línea 20... Línea 20...
20
 
20
 
21
    script.src = url;
21
    script.src = url;
22
    document.getElementsByTagName("head")[0].appendChild(script);
22
    document.getElementsByTagName("head")[0].appendChild(script);
Línea 23... Línea 23...
23
};
23
};
Línea 24... Línea 24...
24
 
24
 
25
function SearchLocationInput({ googleApiKey, setValue, value }) {
25
function SearchLocationInput({ googleApiKey, setValue, value, updateData }) {
26
 
26
 
27
    const autoCompleteRef = useRef(null);
27
    const autoCompleteRef = useRef(null);
Línea 54... Línea 54...
54
        const place = await autoComplete.getPlace()
54
        const place = await autoComplete.getPlace()
55
        console.log(place)
55
        console.log(place)
Línea 56... Línea 56...
56
 
56
 
57
        setData({
57
        setData({
58
            ...data,
58
            ...data,
59
            formatted_address: place.formatted_address,
59
            formatted_address: place.address_components.formatted_address,
60
            latitude: place.geometry.location.lat(),
60
            latitude: place.geometry?.location.lat(),
61
            longitude: place.geometry.location.lng()
61
            longitude: place.geometry?.location.lng()
Línea 62... Línea -...
62
        })
-
 
63
 
62
        })
64
        if (place.geometry) {
63
 
65
            place.address_components.forEach((address_component) => {
64
        place.address_components?.map((address_component) => {
66
                if (address_component.types[0] == "route") {
65
            if (address_component.types[0] == "route") {
67
                    setData({
66
                setData({
68
                        ...data,
67
                    ...data,
69
                        address1: address_component.long_name,
68
                    address1: address_component.long_name
70
                    })
69
                })
71
                }
70
            }
72
                if (address_component.types[0] == "sublocality") {
71
            if (address_component.types[0] == "sublocality") {
73
                    setData({
72
                setData({
74
                        ...data,
73
                    ...data,
75
                        address2: address_component.long_name,
74
                    address2: address_component.long_name
76
                    })
75
                })
77
                }
76
            }
78
                if (address_component.types[0] == "locality") {
77
            if (address_component.types[0] == "locality") {
79
                    setData({
78
                setData({
80
                        ...data,
79
                    ...data,
81
                        city1: address_component.long_name,
80
                    city1: address_component.long_name
82
                    })
81
                })
83
                }
82
            }
84
                if (address_component.types[0] == "administrative_area_level_2") {
83
            if (address_component.types[0] == "administrative_area_level_2") {
85
                    setData({
84
                setData({
86
                        ...data,
85
                    ...data,
87
                        city2: address_component.long_name,
86
                    city2: address_component.long_name
88
                    })
87
                })
89
                }
88
            }
90
                if (address_component.types[0] == "administrative_area_level_1") {
89
            if (address_component.types[0] == "administrative_area_level_1") {
91
                    setData({
90
                setData({
92
                        ...data,
91
                    ...data,
93
                        state: address_component.long_name
92
                    state: address_component.long_name
94
                    })
93
                })
95
                }
94
            }
96
                if (address_component.types[0] == "country") {
95
            if (address_component.types[0] == "country") {
97
                    setData({
96
                setData({
98
                        ...data,
97
                    ...data,
99
                        country: address_component.long_name
98
                    country: address_component.long_name
100
                    })
99
                })
101
                }
100
            }
102
                if (address_component.types[0] == "postal_code") {
101
            if (address_component.types[0] == "postal_code") {
103
                    setData({
102
                setData({
104
                        ...data,
-
 
105
                        postal_code: address_component.long_name
103
                    ...data,
106
                    })
104
                    postal_code: address_component.long_name
107
                }
-
 
108
            })
105
                })
Línea 109... Línea 106...
109
 
106
            }
110
        }
-
 
111
 
107
        })
Línea 112... Línea 108...
112
        updateQuery(place.formatted_address)
108
 
113
 
109
        updateQuery(place.formatted_address)
114
    }
110
    }
115
 
111
 
116
 
112
 
117
    useEffect(() => {
113
    useEffect(() => {
Línea -... Línea 114...
-
 
114
        loadScript(
-
 
115
            `https://maps.googleapis.com/maps/api/js?key=${googleApiKey}&libraries=places`,
-
 
116
            () => handleScriptLoad(setValue, autoCompleteRef, setData)
-
 
117
        );
118
        loadScript(
118
    }, []);
119
            `https://maps.googleapis.com/maps/api/js?key=${googleApiKey}&libraries=places`,
119
 
120
            () => handleScriptLoad(setValue, autoCompleteRef, setData)
120
    useEffect(() => {
121
        );
121
        updateData(data)
122
    }, []);
122
    }, [data]);