Eğik 4 Google Geocoder API

oy
0

Biz satın alınan Google Map API anahtarı var. Bizim Açısal kodunda, biz enlem / boylam listesi için ters coğrafi kodlama yapmak agm / çekirdek açısal kütüphanesini kullanan google.maps.Geocode (). geocode kullanmaya çalışıyoruz. Bir saniye içinde biz geçerli yanıt almak ve web portalında adresi göstermek, böylece 20-30 istekleri etrafında göndermek istedik. OVER_QUERY_LIMIT coğrafi kod API çağrısı: Ama biz aşağıdaki hatayı alıyorsanız.

İşte aynı için kod parçası geçerli:

return Observable.create((observer: Observer<object>) => {
if (geocoder) {
       new google.maps.Geocoder().geocode({ 'location': latlng }, function (results, status) {
       console.log(status);
       if (status === 'OK') {
           console.log(results[0].formatted_address);
       }
    });
}});

Aynı java script kullanarak ve aynı hatayı alıyorum çalıştı. Bu hatayı önlemek için herhangi bir ek parametreler göndermek gerekiyorsa emin değilim. Sorunu çözmede bize rehberlik edebilir miyim teşekkür ederiz.

Şimdiden teşekkürler.

Oluştur 27/02/2018 saat 22:01
kaynak kullanıcı
Diğer dillerde...                            


1 cevaplar

oy
0

topluma burada yardım için bir şans verdiğiniz için teşekkürler. Şimdi, iki farklı şekilde bu sorunu yaklaşabilir. böylece-to-konuşmak, kimse QPS sınırı ulaşmasını tutmak anlamına gelir gibi ben her iki yaklaşımı kullanmayı tercih ediyorum, ve diğer en "olduğunu köprü ve onu geçmeye hazırız" ne zaman durum yönetmenize yardımcı olmaktır .

1) Potansiyel olabilir önbelleğe Google'ın Standart HŞ'de izin verdiği gibi tüm sonuçları.

Google Maps API Şartlar geçici, en fazla 30 günlük bir süre boyunca, Google Maps verileri önbelleğe alabilir uygulamanızın performansını artırmak için belirtir. web hizmeti yanıt önbelleğe olarak, uygulama kısa bir süre boyunca yinelenen istekleri göndermek önleyebilirsiniz. Kamu, max-age = 86400: Aslında, web hizmeti yanıtları her zaman sonuç; örneğin, Cache-Control önbelleğe alabilir hangi dönemini belirten Cache-Control HTTP başlık bulunmaktadır. Verimlilik, uygulamanız her zaman en az bu başlıkta belirtilen zaman ancak Google Maps API Şartlarında belirtilen maksimum süreden fazla sonuçlarını önbelleğe sağlamak.

2) olabilir boğazını açıklandığı gibi yanıtlar arasında rasgele aralıklarla bir zaman aşımı ve / veya seğirme isteklerini kullanarak isteğinizi Google Dokümanlar ve JS Zaman Aşımı tarafından sağlanan aşağıda tam örnek kodu ile @ Andrew Leach .

// delay between geocode requests - at the time of writing, 100 miliseconds seems to work well
var delay = 100;


  // ====== Create map objects ======
  var infowindow = new google.maps.InfoWindow();
  var latlng = new google.maps.LatLng(-34.397, 150.644);
  var mapOptions = {
    zoom: 8,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var geo = new google.maps.Geocoder(); 
  var map = new google.maps.Map(document.getElementById("map"), mapOptions);
  var bounds = new google.maps.LatLngBounds();

  // ====== Geocoding ======
  function getAddress(search, next) {
    geo.geocode({address:search}, function (results,status)
      { 
        // If that was successful
        if (status == google.maps.GeocoderStatus.OK) {
          // Lets assume that the first marker is the one we want
          var p = results[0].geometry.location;
          var lat=p.lat();
          var lng=p.lng();
          // Output the data
            var msg = 'address="' + search + '" lat=' +lat+ ' lng=' +lng+ '(delay='+delay+'ms)<br>';
            document.getElementById("messages").innerHTML += msg;
          // Create a marker
          createMarker(search,lat,lng);
        }
        // ====== Decode the error status ======
        else {
          // === if we were sending the requests to fast, try this one again and increase the delay
          if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
            nextAddress--;
            delay++;
          } else {
            var reason="Code "+status;
            var msg = 'address="' + search + '" error=' +reason+ '(delay='+delay+'ms)<br>';
            document.getElementById("messages").innerHTML += msg;
          }   
        }
        next();
      }
    );
  }

       // ======= Function to create a marker
 function createMarker(add,lat,lng) {
   var contentString = add;
   var marker = new google.maps.Marker({
     position: new google.maps.LatLng(lat,lng),
     map: map,
     zIndex: Math.round(latlng.lat()*-100000)<<5
   });

  google.maps.event.addListener(marker, 'click', function() {
     infowindow.setContent(contentString); 
     infowindow.open(map,marker);
   });

   bounds.extend(marker.position);

 }

  // ======= An array of locations that we want to Geocode ========
  var addresses = [
           '251 Pantigo Road Hampton Bays NY 11946',
           'Amagensett Quiogue NY 11978',
           '789 Main Street Hampton Bays NY 11946',
           '30 Abrahams Path Hampton Bays NY 11946',
           '3 Winnebogue Ln Westhampton NY 11977',
           '44 White Oak Lane Montauk NY 11954',
           '107 stoney hill road Bridgehampton NY 11932',
           '250 Pantigo Rd Hampton Bays NY 11946',
           '250 Pantigo Rd Hampton Bays NY 11946',
           '44 Woodruff Lane Wainscott NY 11975',
           'Address East Hampton NY 11937',
           'Address Amagansett NY 11930',
           'Address Remsenburg NY 11960 ',
           'Address Westhampton NY 11977',
           'prop address Westhampton Dunes NY 11978',
           'prop address East Hampton NY 11937',
           'Address East Hampton NY 11937',
           'Address Southampton NY 11968',
           'Address Bridgehampton NY 11932',
           'Address Sagaponack NY 11962',
            "A totally bogus address"
  ];

  // ======= Global variable to remind us what to do next
  var nextAddress = 0;

  // ======= Function to call the next Geocode operation when the reply comes back

  function theNext() {
    if (nextAddress < addresses.length) {
      setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', delay);
      nextAddress++;
    } else {
      // We're done. Show map bounds
      map.fitBounds(bounds);
    }
  }

  // ======= Call that function for the first time =======
  theNext();
Cevap 28/02/2018 saat 00:36
kaynak kullanıcı

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more