@Test
  public void testReverseGeocodeRestrictedByType() throws Exception {
    try (LocalTestServerContext sc =
        new LocalTestServerContext(
            "\n"
                + "{\n"
                + "   \"results\" : [\n"
                + "      {\n"
                + "         \"address_components\" : [\n"
                + "            {\n"
                + "               \"long_name\" : \"277\",\n"
                + "               \"short_name\" : \"277\",\n"
                + "               \"types\" : [ \"street_number\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"Bedford Avenue\",\n"
                + "               \"short_name\" : \"Bedford Ave\",\n"
                + "               \"types\" : [ \"route\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"Williamsburg\",\n"
                + "               \"short_name\" : \"Williamsburg\",\n"
                + "               \"types\" : [ \"neighborhood\", \"political\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"Brooklyn\",\n"
                + "               \"short_name\" : \"Brooklyn\",\n"
                + "               \"types\" : [ \"political\", \"sublocality\", \"sublocality_level_1\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"Kings County\",\n"
                + "               \"short_name\" : \"Kings County\",\n"
                + "               \"types\" : [ \"administrative_area_level_2\", \"political\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"New York\",\n"
                + "               \"short_name\" : \"NY\",\n"
                + "               \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"United States\",\n"
                + "               \"short_name\" : \"US\",\n"
                + "               \"types\" : [ \"country\", \"political\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"11211\",\n"
                + "               \"short_name\" : \"11211\",\n"
                + "               \"types\" : [ \"postal_code\" ]\n"
                + "            }\n"
                + "         ],\n"
                + "         \"formatted_address\" : \"277 Bedford Ave, Brooklyn, NY 11211, USA\",\n"
                + "         \"geometry\" : {\n"
                + "            \"location\" : {\n"
                + "               \"lat\" : 40.7142205,\n"
                + "               \"lng\" : -73.9612903\n"
                + "            },\n"
                + "            \"location_type\" : \"ROOFTOP\",\n"
                + "            \"viewport\" : {\n"
                + "               \"northeast\" : {\n"
                + "                  \"lat\" : 40.71556948029149,\n"
                + "                  \"lng\" : -73.95994131970849\n"
                + "               },\n"
                + "               \"southwest\" : {\n"
                + "                  \"lat\" : 40.7128715197085,\n"
                + "                  \"lng\" : -73.9626392802915\n"
                + "               }\n"
                + "            }\n"
                + "         },\n"
                + "         \"place_id\" : \"ChIJd8BlQ2BZwokRAFUEcm_qrcA\",\n"
                + "         \"types\" : [ \"street_address\" ]\n"
                + "      }\n"
                + "   ],\n"
                + "   \"status\" : \"OK\"\n"
                + "}\n")) {
      LatLng latlng = new LatLng(40.714224, -73.961452);
      GeocodingResult[] results =
          GeocodingApi.newRequest(sc.context)
              .latlng(latlng)
              .locationType(LocationType.ROOFTOP)
              .resultType(AddressType.STREET_ADDRESS)
              .await()
              .results;

      assertNotNull(results);
      assertNotNull(Arrays.toString(results));
      assertEquals("277 Bedford Ave, Brooklyn, NY 11211, USA", results[0].formattedAddress);
      assertEquals(LocationType.ROOFTOP, results[0].geometry.locationType);
      assertEquals("ChIJd8BlQ2BZwokRAFUEcm_qrcA", results[0].placeId);

      sc.assertParamValue(latlng.toUrlValue(), "latlng");
      sc.assertParamValue(LocationType.ROOFTOP.toUrlValue(), "location_type");
      sc.assertParamValue(AddressType.STREET_ADDRESS.toUrlValue(), "result_type");
    }
  }
Reverse geocode restricted by type: <a
href="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&location_type=ROOFTOP&result_type=street_address">
Reverse Geocode (40.714224,-73.961452) with location type of ROOFTOP and result type of
street_address</a>.
src/test/java/com/google/maps/GeocodingApiTest.java