Google地理编码器在一页上抛出MissingKeyMapError,但不是另一页 [英] Google geocoder throwing MissingKeyMapError on one page but not another

查看:156
本文介绍了Google地理编码器在一页上抛出MissingKeyMapError,但不是另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个基本相同的网站 - 将地址放入数据库中。这两个网站似乎都有相同的代码。但是一页会抛出MissingKeyMapError,而另一页则不会。我没有看到两者之间有太大的区别。任何人都可以帮忙吗?

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?

第一个网站jquery:

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
        });
      }

    }); 
}

第二个网站jquery:

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) {
        });
}

第二页抛出这个错误:
js?sensor = false :32 Google Maps API错误:MissingKeyMapError https:/ /developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

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?

推荐答案

钥匙现在是必需的。 2016年6月22日前没有使用钥匙的活动网站是盛大的,并将继续无钥匙工作(至少现在)。新网站将需要一个密钥。

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.

这篇关于Google地理编码器在一页上抛出MissingKeyMapError,但不是另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆