Google geocoder throwing MissingKeyMapError on one page but not another [duplicate]

混江龙づ霸主 提交于 2019-11-28 12:54:14

问题


I have two websites that do essentially the same thing - take addresses and put them in a database. Both websites seem to have the same code. But one page throws the MissingKeyMapError and the other doesn't. I don't see much difference between the two. Can anyone help please?

First website jquery:

var latlong = [];
//addresses is a long array made up of addresses such as
//"1056 BRUSHTON AVE, Pittsburgh"
var geocoder = new google.maps.Geocoder();
$(document).ready(function() {
    var count = 23963; //the record number in the database
    setInterval(function(){
        if (addresses.length > 0) {
            for (var i=0; i< 11; i++) { //limit of 11 at a time so don't overwhelm API
                var address = addresses[i];
                count++;
                locate(address, count);
            }
            addresses.splice(0, 11); //go to the next 11 addresses
        } else {
            clearInterval();
        }
    }, 30000);
});

function locate(address, count) {
    geocoder.geocode( { 'address': address}, function(results, status) {

      if (status == google.maps.GeocoderStatus.OK) {
        var lat = results[0].geometry.location.lat();
        var lng = results[0].geometry.location.lng();
        $.post('php/push_latlng.php', {address: address, lat: lat, lng: lng, count:count },function(){
               //put it in the database
        });
      }

    }); 
}

Second website jquery:

var latlong = [];
var geocoder = new google.maps.Geocoder();
$(document).ready(function() {
    $.post('php/get_address.php', function(addresses){
    //get addresses out of the database and turn them into json             
    var obj = jQuery.parseJSON( addresses );
            //addresses are in the format "1800 Mulberry St, Scranton, PA"
            for (var i = 0; i< 2; i++) { //arbitrary small number
                var medID = obj[i].medID;
                var address = obj[i].address;
                locate(address, medID);
            }
    });

});
function locate(address, medID) {
    geocoder.geocode( { 'address': address}, function(results, status) {
        });
}

The second page throws this error: js?sensor=false:32 Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

Anyone know what I'm doing wrong?


回答1:


Keys are now required. Sites that were active before June 22, 2016 without keys are "grandfathered" and will continue to work without keys (at least for now). New sites will require a key.



来源:https://stackoverflow.com/questions/38269149/google-geocoder-throwing-missingkeymaperror-on-one-page-but-not-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!