使用会话令牌时未触发Google地方信息自动填充功能(包含在地方信息中) [英] Google Places Autocomplete (included with Places Details) SKU is not getting triggered while using session tokens

查看:68
本文介绍了使用会话令牌时未触发Google地方信息自动填充功能(包含在地方信息中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向Google地方信息自动填充和详细信息api发出请求.对于这两种方式,我都在使用会话令牌免费使用自动完成api收费,但在Google报告中却没有看到Autocomplete (included with Places Details) SKU.我一周前开始使用它,我只看到SKU: Autocomplete without Places Details – Per Session.

I am making requests to the Google places autocomplete and details api. For both I am using session tokens to use the autocomplete api charge free, but I don't see the Autocomplete (included with Places Details) SKU in the Google report. I started using it a week ago and all I see is the SKU: Autocomplete without Places Details – Per Session.

在我的代码中,在向详细信息api发出请求后,我正在生成一个新的符合版本4 UUID的会话令牌.我正在遵循文档中的说明:

In my code I am generating a new version 4 UUID compliant session token after a request to the details api is made. I am following the guidelines in the docs that say this:

所以我正在做确切的事情.但是我没有在报告中看到Autocomplete (included with Place Details).我相信已经打了很多电话.任何想法为什么会发生这种情况?

So I am doing that exact thing. But I don't see the Autocomplete (included with Place Details) in the report. I am sure a lot of calls have been made. Any ideas why this is happening?

注意:我不是使用placeid而是使用place_id参数进行详细信息调用,该参数也可以使用.我不认为这是原因,但是无论如何...

Note: Instead of placeid I am using place_id parameter for the details call which also works. I don't think that's the reason but anyways...

我正在使用此函数来生成会话令牌:

I am using this function to generate the session tokens:

var UUID = (function() {
  var self = {};
  var lut = [];
  for (var i=0; i<256; i++) { lut[i] = (i<16?'0':'')+(i).toString(16); }
  self.generate = function() {
      var d0 = Math.random()*0xffffffff|0;
      var d1 = Math.random()*0xffffffff|0;
      var d2 = Math.random()*0xffffffff|0;
      var d3 = Math.random()*0xffffffff|0;
      return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+
        lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+
        lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+
        lut[d3&0xff]+lut[d3>>8&0xff]+lut[d3>>16&0xff]+lut[d3>>24&0xff];
  }
  return self;
})();

它以如下格式输出字符串:a28cf301-d8fd-4ebd-ac25-a94a37113b6c.

It outputs a string in a format like this: a28cf301-d8fd-4ebd-ac25-a94a37113b6c.

我正在使用传单控件来发出请求.

I am using a leaflet control to make the requests.

每次键入字母时都会调用以下函数:

The following function is called each time a letter is typed:

// Places Autocomplete call
autocomplete: function(e) {
    var mapCenter = this._map.getCenter();
    var url = this.options.url + '/autocomplete?' +
        'input=' + this.input.value + '&' +
        'location=' + mapCenter.lat + ',' + mapCenter.lng;

    if (this.options.useSessions) {
        url += '&sessiontoken=' + this.sessionToken;
    }

    var geocoder = this;

    $.get(url, function(data, status) {
        if (data === undefined || data.status !== 'OK') {
            return;
        }

        // Use predictions to populate a list
    });
},

该函数使用预测填充列表,并将click事件侦听器添加到每个列表项.单击一个项目时,将调用以下功能.

That function populates a list with the predictions and add click event listeners to each list item. When an item is clicked the following function is called.

// Place Details request
focusSelected: function(e) {
    var url = this.options.url + '/details?' +
        'place_id=' + e.target.place_id;

    if (this.options.useSessions) {
        url += '&sessiontoken=' + this.sessionToken;
        this.sessionToken = UUID.generate(); // This creates a new token
    }

    var geocoder = this;
    $.get(url, function(data, status) {
        if (data === undefined || data.status !== 'OK') {
            return;
        }

        // Use result

    });
},

我还在每个调用中设置API密钥.别介意.

I am also setting the API key in each call. Don't mind about that.

推荐答案

如果在开始会话后的几分钟内没有完成Places Details请求,则会看到Autocomplete without Places Details – Per Session.

You will see Autocomplete without Places Details – Per Session if you don't complete a Places Details request within a few minutes of starting the session.

https://developers .google.com/maps/billing/understanding-cost-of-use#ac-no-details-session

这篇关于使用会话令牌时未触发Google地方信息自动填充功能(包含在地方信息中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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