Commute search

Job search requests can include a commute time filter that restricts returned jobs to those within a specified travel time from a start point. Results include the estimated commute time in seconds for matched jobs.

To return jobs within a specific commute time, send a jobs.search request and include a CommuteFilter object in the JobQuery.commuteFilter field. Cloud Talent Solution uses the job’s address to calculate the commute time to that job. When a detailed address is not provided Cloud Talent Solution attempts to infer the actual street address of the job.

Java

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

public static void commuteSearch(String companyName) throws IOException {
  // Make sure to set the requestMetadata the same as the associated search request
  RequestMetadata requestMetadata =
      new RequestMetadata()
          // Make sure to hash your userID
          .setUserId("HashedUserId")
          // Make sure to hash the sessionID
          .setSessionId("HashedSessionID")
          // Domain of the website where the search is conducted
          .setDomain("www.google.com");
  JobQuery jobQuery =
      new JobQuery()
          .setCommuteFilter(
              new CommuteFilter()
                  .setRoadTraffic("TRAFFIC_FREE")
                  .setCommuteMethod("TRANSIT")
                  .setTravelDuration("1000s")
                  .setStartCoordinates(
                      new LatLng().setLatitude(37.422408)
                          .setLongitude(-122.085609)));
  if (companyName != null) {
    jobQuery.setCompanyNames(Arrays.asList(companyName));
  }

  SearchJobsRequest searchJobsRequest =
      new SearchJobsRequest()
          .setJobQuery(jobQuery)
          .setRequestMetadata(requestMetadata)
          .setJobView("JOB_VIEW_FULL")
          .setRequirePreciseResultSize(true);
  SearchJobsResponse response =
      talentSolutionClient.projects().jobs().search(DEFAULT_PROJECT_ID, searchJobsRequest)
          .execute();
  System.out.println(response);
}

Python

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

def commute_search(client_service, company_name):
    request_metadata = {
        'user_id': 'HashedUserId',
        'session_id': 'HashedSessionId',
        'domain': 'www.google.com'
    }
    start_location = {'latitude': 37.422408, 'longitude': -122.085609}
    commute_preference = {
        'road_traffic': 'TRAFFIC_FREE',
        'commute_method': 'TRANSIT',
        'travel_duration': '1000s',
        'start_coordinates': start_location
    }
    job_query = {'commute_filter': commute_preference}
    if company_name is not None:
        job_query.update({'company_names': [company_name]})
    request = {
        'job_query': job_query,
        'request_metadata': request_metadata,
        'job_view': 'JOB_VIEW_FULL',
        'require_precise_result_size': True
    }
    response = client_service.projects().jobs().search(
        parent=parent, body=request).execute()
    print(response)

C#

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

public static void CommuteSearch(string companyName)
{
    RequestMetadata requestMetadata = new RequestMetadata()
    {
        // Make sure to hash your userID
        UserId = "HashedUserId",
        // Make sure to hash the sessionID
        SessionId = "HashedSessionId",
        // Domain of the website where the search is conducted
        Domain = "www.google.com"
    };

    JobQuery jobQuery = new JobQuery()
    {
        CommuteFilter = new CommuteFilter()
        {
            RoadTraffic = "TRAFFIC_FREE",
            CommuteMethod = "TRANSIT",
            TravelDuration = "1000s",
            StartCoordinates = new LatLng()
            {
                Latitude = 37.42208,
                Longitude = -122.085609
            }
        }
    };

    if (companyName != null)
    {
        jobQuery.CompanyNames = new List<string>
        {
            companyName
        };
    }

    SearchJobsRequest searchJobRequest = new SearchJobsRequest()
    {
        RequestMetadata = requestMetadata,
        JobQuery = jobQuery,
        JobView = "JOB_VIEW_FULL",
        RequirePreciseResultSize = true
    };

    SearchJobsResponse searchJobsResponse = jobServiceClient.Projects.Jobs.Search(searchJobRequest, parent).Execute();

    Console.WriteLine("Jobs commute searched: " + ToJsonString(searchJobsResponse));
}

Go

For more on installing and creating a Cloud Talent Solution client, see Cloud Talent Solution Client Libraries.

// commuteSearch searches for jobs within commute filter.
func commuteSearch(service *talent.Service, parent string, companyName string) (*talent.SearchJobsResponse, error) {
	// Make sure to set the requestMetadata the same as the associated search request
	requestMetadata := &talent.RequestMetadata{
		// Make sure to hash your userID
		UserId: "HashedUsrId",
		// Make sure to hash the sessionID
		SessionId: "HashedSessionId",
		// Domain of the website where the search is conducted
		Domain: "www.googlesample.com",
	}
	jobQuery := &talent.JobQuery{
		CommuteFilter: &talent.CommuteFilter{
			RoadTraffic:    "TRAFFIC_FREE",
			CommuteMethod:  "TRANSIT",
			TravelDuration: "1000s",
			StartCoordinates: &talent.LatLng{
				Latitude:  37.422408,
				Longitude: -122.085609,
			},
		},
	}
	if companyName != "" {
		jobQuery.CompanyNames = []string{companyName}
	}

	searchJobsRequest := &talent.SearchJobsRequest{
		RequestMetadata: requestMetadata,
		// Set the actual search term as defined in the jobQurey
		JobQuery: jobQuery,
		// Set the search mode to a regular search
		SearchMode:               "JOB_SEARCH",
		RequirePreciseResultSize: true,
	}
	resp, err := service.Projects.Jobs.Search(parent, searchJobsRequest).Do()
	if err != nil {
		return nil, fmt.Errorf("failed to search for jobs with commute filter: %v", err)
	}
	return resp, nil
}

Required fields

  • commuteMethod: The method of transportation for which to calculate the commute time. One of DRIVING or TRANSIT.

  • travelDuration: The maximum travel time in seconds. The maximum allowed value is 3600s (one hour). Format is 123s.

  • startCoordinates: The latitude and longitude of the location from which to calculate the commute time. Accepts a LatLng object.

Optional fields

  • allowImpreciseAddresses: If true, jobs without explicitly passed (or inferred) street level addresses may also be returned. For city level addresses, the city center is used. For state and coarser level addresses, text matching is used. If this field is set to false or is not specified, only jobs that include street level addresses are returned by commute search.

  • roadTraffic: Specifies the traffic density to use when calculating commute time. Options are TRAFFIC_FREE or BUSY_HOUR. Must not be present if departureHourLocal is specified.

  • departureTime: The departure hour to use to calculate traffic impact. Accepts an integer between 0 and 23, representing the hour in the timezone of the startLocation. Must not be present if roadTraffic is specified.

Was this page helpful? Let us know how we did:

Send feedback about...

Job search documentation