简体   繁体   English

谷歌地图中的函数(响应,状态)是什么意思?

[英]what does the function(respsonse,status) mean in google maps?

I am trying to create a route planner for a school project and I need to annotate my code to explain what it means/does.我正在尝试为学校项目创建路线规划器,我需要注释我的代码以解释它的含义/作用。 Since my JavaScript/Google Maps knowledge is limited and I can't find anything on here, I was wondering what does the following code do/mean.由于我的 JavaScript/Google Maps 知识有限,我在这里找不到任何东西,我想知道以下代码的作用/含义是什么。

function(response, status) {
      if (status === 'OK') {
        directionsDisplay.setDirections(response);

By the names of the parameters in your function I infer it is related to HTTP requests, responses and status.根据您函数中参数的名称,我推断它与 HTTP 请求、响应和状态有关。

In HTTP, a response is the complete (as its name states) response of a request, the status is one of many different HTTP status, it has an equivalent status code.在 HTTP 中,响应是请求的完整(正如其名称所述)响应,状态是许多不同的 HTTP 状态之一,它具有等效的状态代码。 You can learn about them everywhere .您可以在任何地方了解它们。

A status 200 means OK which is the one in your condition.状态200表示OK ,这是您的情况。 You may be familiar with the following status:您可能熟悉以下状态:

  1. 404 : Not found 404 :未找到
  2. 500 : Internal server error 500 :内部服务器错误

In your function, response may be the result of a HTTP call containing some valuable data that you bounce to the function directionsDisplay.setDirections .在您的函数中, response可能是包含一些有价值数据的 HTTP 调用的结果,您将这些数据反弹到函数directionsDisplay.setDirections

Exactly what it does depends on the rest of your code.它的确切作用取决于您的代码的其余部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM