将Google地图自动填充结果分配给变量的问题

时间:2014-06-20 16:52:28

标签: google-maps

我对这一行有疑问:     var user-city = addressObj [j] .long_name; 我在控制台日志中看到了正确的值,但无法将其分配给变量。

function onPlaceChanged() {


    var places = autocomplete.getPlace();
    //console.log(places);
    //    var place = places[0];
    console.log(places);
    console.log(places.address_components);
    user_home_address = places.name;


for(var i = 0; i < places.address_components.length; i += 1) {
  var addressObj = places.address_components[i];

  for(var j = 0; j < addressObj.types.length; j += 1) {
    if (addressObj.types[j] === 'locality') {
      // console.log(addressObj.types[j]); // confirm that this is 'city'
     var user-city = addressObj[j].long_name;
      // console.log(addressObj.long_name); // confirm that this is the city name

    }
  }

  for(var j = 0; j < addressObj.types.length; j += 1) {
    if (addressObj.types[j] === 'administrative_area_level_1') {
      // console.log(addressObj.types[j]); // confirm that this is 'province'
      // console.log(addressObj.short_name); // confirm that this is the province name

    }
  }


}

0 个答案:

没有答案