我可以将Google Maps API自动填充结果限制在爱尔兰和北爱尔兰吗?

时间:2017-10-28 10:43:28

标签: google-maps-api-3

目前我可以将结果限制在爱尔兰和英国(GB),但我需要将结果限制在爱尔兰岛(爱尔兰和北爱尔兰),但由于北爱尔兰是英国的一部分我得到了结果整个英国使用国家代码即& GB

但我怎么能将这个限制在国家 - 爱尔兰和地区 - 北爱尔兰?

感谢您的提前帮助

var countryCodes = [' ie',' gb'];

-Djava.rmi.server.hostname=127.0.0.1

2 个答案:

答案 0 :(得分:0)

12. Maps API Standard Pricing Plan 12.1免费配额。本服务的某些部分免费提供给您,最高可达Maps API文档中描述的交易限制。

我认为不受国家限制

每天25000次下载:   - Google Maps JavaScript API   - Google Static Maps API   - Google街景图片API

每天2500次请求:   - Google Maps Directions API   - Google Maps Distance Matrix API 4   - Google Maps Elevation API   - Google Maps Geocoding API   - Google Maps Geolocation API   - Google Maps Roads API   - Google Maps时区API

contact Sales如果需要更多..

答案 1 :(得分:0)

目前无法在自动填充的地方添加管理区域过滤器。您的用例的唯一解决方法是定义包含爱尔兰和北爱尔兰的边界,并在autocomplete options中将这些边界与function throttle(f, delay){ var timer = null; return function(){ var context = this, args = arguments; clearTimeout(timer); timer = window.setTimeout(function(){ f.apply(context, args); }, delay || 500); }; } $('#search').keyup(throttle(function(){ // do ajax })); 参数一起设置为true。

概念证明

strictBounds
function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 53.435719, lng: -7.77832},
    zoom: 6,
    scaleControl: true
  });
  
  var irelandBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(50.999929,-10.854492),
    new google.maps.LatLng(55.354135,-5.339355));
    
  map.fitBounds(irelandBounds);  
  
  var boundsPoly = new google.maps.Polyline({
    map: map,
    path: [
      {lat: irelandBounds.getSouthWest().lat(), lng: irelandBounds.getSouthWest().lng()},
      {lat: irelandBounds.getSouthWest().lat(), lng: irelandBounds.getNorthEast().lng()},
      {lat: irelandBounds.getNorthEast().lat(), lng: irelandBounds.getNorthEast().lng()},
      {lat: irelandBounds.getNorthEast().lat(), lng: irelandBounds.getSouthWest().lng()},
      {lat: irelandBounds.getSouthWest().lat(), lng: irelandBounds.getSouthWest().lng()}
    ],
    strokeColor: "#FF0000"
  });

  
  var input = /** @type {!HTMLInputElement} */(
      document.getElementById('pac-input'));

  map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
  
  var autocomplete = new google.maps.places.Autocomplete(input, {
    bounds: irelandBounds,
    strictBounds: true
  });

  var infowindow = new google.maps.InfoWindow();
  var marker = new google.maps.Marker({
    map: map,
    anchorPoint: new google.maps.Point(0, -29)
  });

  autocomplete.addListener('place_changed', function() {
    infowindow.close();
    marker.setVisible(false);
    var place = autocomplete.getPlace();
    if (!place.geometry) {
      window.alert("Autocomplete's returned place contains no geometry");
      return;
    }

    // If the place has a geometry, then present it on a map.
    if (place.geometry.viewport) {
      map.fitBounds(place.geometry.viewport);
    } else {
      map.setCenter(place.geometry.location);
      map.setZoom(17);  // Why 17? Because it looks good.
    }
    marker.setIcon(/** @type {google.maps.Icon} */({
      url: place.icon,
      size: new google.maps.Size(71, 71),
      origin: new google.maps.Point(0, 0),
      anchor: new google.maps.Point(17, 34),
      scaledSize: new google.maps.Size(35, 35)
    }));
    marker.setPosition(place.geometry.location);
    marker.setVisible(true);

    var address = '';
    if (place.address_components) {
      address = [
        (place.address_components[0] && place.address_components[0].short_name || ''),
        (place.address_components[1] && place.address_components[1].short_name || ''),
        (place.address_components[2] && place.address_components[2].short_name || '')
      ].join(' ');
    }

    infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
    infowindow.open(map, marker);
  });
}
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
.controls {
  margin-top: 10px;
  border: 1px solid transparent;
  border-radius: 2px 0 0 2px;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  height: 32px;
  outline: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

#pac-input {
  background-color: #fff;
  font-family: Roboto;
  font-size: 15px;
  font-weight: 300;
  margin-left: 12px;
  padding: 0 11px 0 13px;
  text-overflow: ellipsis;
  width: 300px;
}

#pac-input:focus {
  border-color: #4d90fe;
}

.pac-container {
  font-family: Roboto;
}

我希望这有帮助!