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
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,
});