Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I getting this error "Object literal may only specify known properties, and 'target' does not exist in type 'CameraConfig'"

I just got my code from another computer and this error shows up, I have been searching for some info but I dont know how to fix it, what Im trying to do here is to add a search bar in my google maps page

  async onSearch(event: any) {
    const query = event.target.value;

    if (query) {
      const geocodeUrl = ``;
      
      try {
        const response = await fetch(geocodeUrl);
        const data = await response.json();

        if (data.status === 'OK') {
          const location = data.results[0].geometry.location;
          this.map.setCamera({
            target: {
              lat: location.lat,
              lng: location.lng,
            },
            zoom: 15,
          });
        } else {
          console.error('No results found for the specified address.');
        }
      } catch (error) {
        console.error('Error fetching geocode:', error);
      }
    }
  }

}

I am using angular version 18.0.0 and ionic 8

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Looking at the documentation Camera Config Type – Capacitor Docs. You should replace target with coordinate and the typescript error will go away.

    ...
    if (data.status === 'OK') {
      const location = data.results[0].geometry.location;
      this.map.setCamera({
        coordinate: { // <- changed here!
          lat: location.lat,
          lng: location.lng,
        },
        zoom: 15,
      });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading