Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
TypeError: Cannot read properties of undefined (reading 'lat') using React version-18 @react-google-maps/api with Rapid Api

I am new to React Google Maps. I am using this library to create a map with several locations and trying fit the boundaries and center it. I am using it to locate restaurants, hotels and all on that particular location.

This is my code in which i am getting error as well as I am getting TypeError: Cannot read properties of undefined (reading 'lat') console.log(bounds.sw, bounds.ne) == undefined console.log(data) == undefined

App.js

function App(){
    const [places, setPlaces] = useState([]);
      const [coordinates, setCoordinates] = useState({});
      const [bounds, setBounds] = useState({});
    
      useEffect(() => {
        // this use effect for detecting current location
        navigator.geolocation.getCurrentPosition(({ coords:{latitude, longitude} }) => {
          setCoordinates({ lat: latitude, lng: longitude });
          // console.log(latitude,longitude)
        })
      },[]);
    
      useEffect(() => {
        getPlacesData(bounds.sw, bounds.ne)
          // console.log(bounds.sw, bounds.ne)
           .then((data)=>{
            //  console.log(data);
             setPlaces(data)
           })
      },[coordinates, bounds]);
     return(<>
            <Map 
                    setCoordinates={setCoordinates}
                    setBounds = {setBounds}
                    coordinates = {coordinates}
                  />
              <>
              )}

Api.js

import axios from 'axios';

const URL = 'https://travel-advisor.p.rapidapi.com/restaurants/list-in-boundary'


export const getPlacesData = async(sw, ne) =>{
    try {
        const {data:{data}} = await axios.get(URL, {
          params: {
            bl_latitude: sw.lat,
            tr_latitude: ne.lat,
            bl_longitude: sw.lng,
            tr_longitude: ne.lng,
          },
          headers: {
            'X-RapidAPI-Host': 'travel-advisor.p.rapidapi.com',
            'X-RapidAPI-Key': 'Key'
          }
        });
        return data;
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda