ERROR TypeError: Cannot read property 'reverseGeocode' of undefined

Hello guy…
I’ve got an issue about ‘reverseGeocode’
And I need your help. Thanks in advance
This is my Typescript file:

` ngAfterViewInit(){

 this.mape = tt.map({
  key: myKey,
  container: 'mape',
  style: 'tomtom://raster/1/basic-main',
  
  draggable:true,
  
  center:{lat:-8.7832,lng:34.5085},
 

});
this.onLastfunction()

}

onClickmap(makerCoord,pop){
const img=document.createElement(‘img’)
img.src=“https://icn.lycee-valin.fr/projets1/seconde14/groupe1/svg.svg
img.style.width=“28px”
img.style.height=“28px”
this.marker=new tt.Marker(img,{draggable:true})
.setLngLat(makerCoord).setPopup(pop).addTo(this.mape)

}

ondrawPassengerMarkerOnMap(geoResponse){
if(
geoResponse && geoResponse.addresses
&& geoResponse.addresses[0].address.freeformAddress
){
this.passMaker=this.onClickmap(geoResponse.addresses[0].position,
new tt.Popup({ offset: 35 })
.setHTML(geoResponse.addresses[0].address.freeformAddress))
this.passMaker.togglePopup();
}
}

onLastfunction(){
this.mape.on(‘click’,(e)=>{
const position=e.lngLat;
console.log(position);

  tt.services.reverseGeocode({
    key: myKey,
    position: position
}).go().then((resu)=>{
  this.ondrawPassengerMarkerOnMap(resu);
})

 })

}
`

Can you also show your imports?

1 Like

import tt from ‘@tomtom-international/web-sdk-maps’;

import {services} from ‘@tomtom-international/web-sdk-services’

OK, in that case try to use services this way:

services.reverseGeocode(...)
2 Likes

Hello guy…
Sorry for the inconvenience
I’ve got other issue about “togglePopup”

Subscriber.js:183 ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘togglePopup’ of undefined
TypeError: Cannot read property ‘togglePopup’ of undefined
at MapModalComponent.ondrawPassengerMarkerOnMap (map-modal.component.ts:110)

I use the same codes…

You are assigning this.passMaker to the result of onClickmap, which is not returning anything…
Then you are trying to run togglePopup(), which is a method of a Marker.
So probably you’d like to do

this.marker.togglePopup();