Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 获取位置类型错误:\ this.map.addEventListener不是ionic中的函数_Google Maps_Ionic3 - Fatal编程技术网

Google maps 获取位置类型错误:\ this.map.addEventListener不是ionic中的函数

Google maps 获取位置类型错误:\ this.map.addEventListener不是ionic中的函数,google-maps,ionic3,Google Maps,Ionic3,在地图中拖动标记时,我试图获取位置坐标。为此,我使用了addEventListener并尝试了this.map.one(),this.map.on()方法来获取纬度和经度。同时,以下类型的错误也会发生 获取位置类型错误:\ this.map.addEventListener不是函数 这是我的密码 this.geolocation.getCurrentPosition().then((resp) => { console.log('latitude',resp.coords.l

在地图中拖动标记时,我试图获取位置坐标。为此,我使用了addEventListener并尝试了this.map.one()this.map.on()方法来获取纬度和经度。同时,以下类型的错误也会发生

获取位置类型错误:\ this.map.addEventListener不是函数

这是我的密码

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

      console.log('latitude',resp.coords.latitude);
      console.log('longitude',resp.coords.longitude);

      let pos = {
        lat: resp.coords.latitude,
        lng: resp.coords.longitude
      };
      this.map = new google.maps.Map(document.getElementById('map'), {
        center: { lat: resp.coords.latitude, lng: resp.coords.longitude },
        zoom: 15
      });

      let marker = new google.maps.Marker({
        position: pos,
        map: this.map,
        draggable:true,
        title: 'I am here!',
      });

      console.log(pos);

      this.markers.push(marker);
      this.map.setCenter(pos);

      this.map.addEventListener(GoogleMapsEvent.MARKER_DRAG_END).subscribe(() => {
        this.map.getCameraPosition().then((cameraPosition) => {
          this.temp = JSON.stringify(cameraPosition.target);
          this.temp2 = JSON.parse(this.temp);
          this.currentLatitude = this.temp2.lat;
          this.currentLongitude = this.temp2.lng;
          let geocoder = new google.maps.Geocoder();
          let latlng = new google.maps.LatLng(this.currentLatitude, this.currentLongitude);
          let request = { latLng: latlng };
          geocoder.geocode(request, (results, status) => {
            if (status == google.maps.GeocoderStatus.OK) {
              if (results[0] != null) {
                let address = results[0].formatted_address;
                this.locationObject = address;
              } else { alert("No address available"); }
            }
          });
        });
      });



    }).catch((error) => {
      console.log('Error getting location', error);
    });

我不知道我哪里做错了,请给我一些建议。
提前感谢

我也在这个阶段挣扎了一周,最后我尝试分别调用每个方法,这听起来不错。你可以试试这个方法

这是初始化和调用映射的方法

this.geolocation.getCurrentPosition().then((response) => {
  console.log('latitude',response.coords.latitude);
  console.log('longitude',response.coords.longitude);

  let position = {
    lat: response.coords.latitude,
    lng: response.coords.longitude
  };
  this.map = new google.maps.Map(document.getElementById('map'), {
    center: { lat: response.coords.latitude, lng: response.coords.longitude },
    zoom: 15
  });

 this.addMarker();
  console.log(position);

}).catch((error) => {
  console.log('Error getting location', error);
});
标记的下一个调用方法

addMarker(){
    let marker = new google.maps.Marker(
    {
     map: this.map,
     draggable: true,
     animation: google.maps.Animation.DROP,
     position: this.map.getCenter()
        });
    let content = "<h4>Whatever you want to display!</h4>";   
    this.addInfoWindow(marker, content);
}
addInfoWindow(marker, content)
{
    let infoWindow = new google.maps.InfoWindow(
    {
    content: content
    });

   google.maps.event.addListener(marker, 'click', () => 
    {
    infoWindow.open(this.map, marker);
    });

   google.maps.event.addListener(marker, 'dragend', function(){
       this.markerlatlong = marker.getPosition();
       console.log("latitude  => "+marker.getPosition().lat());
       console.log("longitude => "+marker.getPosition().lng());
   });
}