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
.
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:
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?
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;
})();
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
});
},
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
});
},
I am also setting the API key in each call. Don't mind about that.
答案 0 :(得分:0)
如果在会话开始后的几分钟内没有完成Autocomplete without Places Details – Per Session
请求,您将看到Places Details
。
https://developers.google.com/maps/billing/understanding-cost-of-use#ac-no-details-session