地理编码请求 - 如何在componentRestrictions中添加多个管理区域?

时间:2014-01-09 12:56:46

标签: javascript google-maps google-maps-api-3 geocoding google-geocoding-api

根据Documentation,我们可以在componentRestrictions中使用administrative_area_level_1,administrative_area_level_2等。

那么如何在下面的代码中分别将state和District添加为administrative_area_level_1和administrative_area_level_2?

function codeAddress() {
  var address = document.getElementById('address').value;
  geocoder.geocode( { 'address': address,
                    'componentRestrictions':{'country':'india'}
  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
      var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
      });
    } else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  });
}

0 个答案:

没有答案