gpt4 book ai didi

performance - 我可以减少 Google Maps JavaScript API v3 中的请求量吗?

转载 作者:行者123 更新时间:2023-12-02 21:57:44 24 4
gpt4 key购买 nike

我调用 2 个地点。我从 xml 文件中获取某个位置的经度和经度。首先是最近的咖啡馆,然后是最近的学校。

$.get('https://maps.googleapis.com/maps/api/place/nearbysearch/xml?
location='+home_latitude+','+home_longtitude+'&rankby=distance&types=cafe&sensor=false&key=X',function(xml)
{
verander($(xml).find("result:first").find("geometry:first").find("location:first").find("lat").text(),$(xml).find("result:first").find("geometry:first").find("location:first").find("lng").text());
}
);

$.get('https://maps.googleapis.com/maps/api/place/nearbysearch/xml?
location='+home_latitude+','+home_longtitude+'&rankby=distance&types=school&sensor=false&key=X',function(xml)
{
verander($(xml).find("result:first").find("geometry:first").find("location:first").find("lat").text(),$(xml).find("result:first").find("geometry:first").find("location:first").find("lng").text());
}
);

但正如你所看到的,我执行了函数 verander(latitude,longtitude) 两次。

function verander(google_lat, google_lng)
{
var bryantPark = new google.maps.LatLng(google_lat, google_lng);
var panoramaOptions =
{
position:bryantPark,
pov:
{
heading: 185,
pitch:0,
zoom:1,
},
panControl : false,
streetViewControl : false,
mapTypeControl: false,
overviewMapControl: false ,
linksControl: false,
addressControl:false,
zoomControl : false,
}
map = new google.maps.StreetViewPanorama(document.getElementById("map_canvas"), panoramaOptions);
map.setVisible(true);
}

是否可以仅在一个请求中推送这 2 个位置(也许通过数组)?我知道这听起来很愚蠢,但我真的想知道它们是否是减少这些谷歌地图请求的后门。

FTR:这是向 Google 发出的请求:

在适用于 Maps API 的使用限制的背景下,什么构成“ map 加载”?在以下情况下会发生单个 map 加载:

  • a。当网页或应用程序加载 map 时,使用 Maps JavaScript API(V2 或 V3)显示 map ;

  • b。未显示 map 的网页或应用程序使用 Maps JavaScript API(V2 或 V3)显示街景全景图;

  • c.加载 Maps API for Flash 的 SWF 由网页或应用程序加载;

  • d。从静态 map API 发出对 map 图像的单个请求。

  • e。从街景图像 API 发出对全景图像的单个请求。

所以恐怕这是不可能的,但是嘿,建议总是受欢迎的!

最佳答案

您调用两次 api 并加载街景两次。所以这是四个调用,但我认为如果您将这两个街景加载到一页上,它们只会将其计为一次。而且您的地方调用将在客户端进行,因此它们不会计入您的限制。

但是要回答你的问题,没有漏洞可以绕过双重负载,因为你想向用户展示两个街景。

我要做的就是在客户提出要求之前不加载任何内容。相反,有几个号召性用语类型按钮,例如 <button onclick="loadStreetView('cafe')">Click here to see Nearby Cafe</button>单击时,它们将调用附近的搜索并加载街景。而且由于它仅根据客户端请求加载,因此您的页面加载永远不会像搜索引擎抓取您的网站时那样增加使用计数。

有关这些使用限制的更多信息

Google Places API 的用途与 map 不同。 https://developers.google.com/places/policies#usage_limits

  • Users with an API key are allowed 1 000 requests per 24 hour period
  • Users who have verified their identity through the APIs console are allowed 100 000 requests per 24 hour period. A credit card is required for verification, by enabling billing in the console. We ask for your credit card purely to validate your identity. Your card will not be charged for use of the Places API.

如果您验证自己的话,每天会收到 100,000 个请求。这相当不错。

对于 Google map ,https://developers.google.com/maps/faq#usagelimits

上面写着,您每天会加载 25,000 次 map 。

In order to accommodate sites that experience short term spikes in usage, the usage limits will only take effect for a given site once that site has exceeded the limits for more than 90 consecutive days.

所以,如果你稍微超过一点,那么他们似乎不会介意。


附: zoom:1 之后多了一个逗号和zoomControl : false他们不应该在那里。在某些浏览器如IE中会导致错误。您还缺少 var panoramaOptions = { ... } 之后的分号和之前 map = new

关于performance - 我可以减少 Google Maps JavaScript API v3 中的请求量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17471220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com