Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
Javascript Google MAP Places API不返回lat lang_Javascript_Angular - Fatal编程技术网

Javascript Google MAP Places API不返回lat lang

Javascript Google MAP Places API不返回lat lang,javascript,angular,Javascript,Angular,我正在使用谷歌地图的地方API和自动完成功能。下面是示例代码 this.autocomplete = new google.maps.places.Autocomplete(this.autocompleteElement.nativeElement,{ componentRestrictions:{'country':'IN'}, types:[] }); // Bind the map's bounds (viewport) property to

我正在使用谷歌地图的地方API和自动完成功能。下面是示例代码

 this.autocomplete = new google.maps.places.Autocomplete(this.autocompleteElement.nativeElement,{
      componentRestrictions:{'country':'IN'},
      types:[]
    });
    // Bind the map's bounds (viewport) property to the autocomplete object,
    // so that the autocomplete requests use the current map bounds for the
    // bounds option in the request.
    //this.autocomplete.bindTo('bounds', map);

    // Set the data fields to return when the user selects a place.
    this.autocomplete.setFields(
      ['address_components', 'geometry.location', 'icon']);


    this.autocomplete.addListener('place_changed',()=>{
      let place=this.autocomplete.getPlace();
      console.log(place);
      if (!place.geometry) {
        // User entered the name of a Place that was not suggested and
        // pressed the Enter key, or the Place Details request failed.
        console.log("No details available for input: '" + place.name + "'");
        return;
      }



    })

无论何时调用gePlace(),它都只返回name属性。请指点。

我相信您可以使用place\u id获得此信息

在if语句中尝试以下操作:

var geocoder = new google.maps.Geocoder();

geocoder.geocode({ 'placeId': place.place_id }, function (results, status)
{
    // return if there was a problem
    if (status !== 'OK') return;

    // get the co-ordinates
    var lat = results[0].geometry.location.lat();

    var lng = results[0].geometry.location.lng();
});