有没有限制的免费Excel Addin Geocoder?

时间:2014-03-24 22:07:22

标签: excel google-maps add-in geocoding yahoo-api

我有大约10K city,st,zip rows。我需要Lat / Long。我尝试了一些不同的插件,但他们都使用谷歌。我听说雅虎有一些更慷慨的限制,但我找不到任何像谷歌那样好的文章。是否有任何免费的批量地理编码器用于excel有很高的限制(每天至少要求10K)?还是我只是在旅行癖?

1 个答案:

答案 0 :(得分:1)

使用此代码,它对我有用,我在网上找到了同样的问题 您可能需要扭曲它以符合您的特定要求,并从excel提供地址数组。

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


  // ====== 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 = [
           'General Roberto Fierro Airport Zona Hangares hangar 12 CHIHUAHUA MEXICO ',
'DURANGO MEXICO ', 'ENSENADA MEXICO ', 'GUADALAJARA MEXICO ', 'GUAYMAS MEXICO ',     'HERMOSILLO MEXICO ', 'HUATULCO MEXICO ', 'LA PAZ MEXICO ', 'LORETO MEXICO ','LOS MOCHIS     MEXICO ',
'MANZANILLO MEXICO ', 'MATAMOROS MEXICO ', 'MAZATLAN MEXICO ', 'MERIDA MEXICO ',
'MEXICALI MEXICO ', 'MINATITLAN MEXICO ', 'MONCLOVA MEXICO '      ];

  // ======= 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();
}