Unable to set click using javascript api for google map to be used in browser


#1

hello, i want to get lat-long co-ordination when user clicks on map, but when i tried to do so i’m getting error like _this.map.on is not a function i have also tried this.map.one but still i’m getting same error. can any one help me? to set on click event on map and get lat-long from map which is javascript api based (not native) used on browser. and also getting error in setClickable
_this.map.setClickable is not a function and this.map.clear is not a function, here is my code

initMap() {

    this.mapInitialised = true;

    this.geolocation.getCurrentPosition().then((position) => {

      console.log("lat " + position.coords.latitude + " long " + position.coords.longitude)

      let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

      let mapOptions = {
        center: latLng,
        zoom: 15,
        mapTypeControl: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        clickableIcons: false,
        disableDefaultUI: true,
        zoomControl: false,
      }

      this.map = new google.maps.Map(document.getElementById("map"), mapOptions);

       var longClick = google.maps.event.MAP_CLICK;

       this.map.on(longClick, function (latLng) {

        var selectedLatLocation = latLng.lat.toString();
        var selectedLongLocation = latLng.lng.toString();

        alert(selectedLatLocation + " " + selectedLongLocation);


      });
     
      this.map.one(google.maps.event.MAP_READY)
      .then(() => {
        console.log('Map is ready!');

        this.map.on(google.maps.event.MAP_CLICK).subscribe(
            (data) => {
                alert("Click MAP");
            }
        );
      });
     this.map.setClickable(true);
   
    });

  }