map.setClickable is not a function in ionic

扶醉桌前 提交于 2019-12-13 13:46:00

问题


I want to get lat-long co-ordination when user clicks on map. However, when I tried to do so I’m getting an error like the following:

_this.map.on is not a function.

I have also tried this.map.one but still I’m getting the same error. Can any one help me? to set an on click event on map and get lat-long from map which is JavaScript API based (not native) used on browser.

I am also getting the following error in setClickable:

_this.map.setClickable 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);

    });

  }

来源:https://stackoverflow.com/questions/49977992/map-setclickable-is-not-a-function-in-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!