title: Find coordinates within a radius with Criteria api
body: <p>I need to fetch all the rows from database where the (latitude and longitude) are within a distance(ex: 10 Km) from a given latitude and longitude (user location) using CriteriaBuilder. </p>
  
  <p>in the third if , I have to fetch the results and add it to predicate.</p>
  
  <pre><code>        CriteriaBuilder cb = em.getCriteriaBuilder();
          CriteriaQuery&lt;Issue&gt; cq = cb.createQuery(Issue.class);
  
          Root&lt;Issue&gt; issue = cq.from(Issue.class);
          List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
  
          if (filters.getCategoryId() != null) {
              Category issueCategory = categoryRepository.findById(filters.getCategoryId())
                      .orElseThrow(() -&gt; new ResourceNotFoundException("Category not found for this id :: " +String.valueOf(filters.getCategoryId())));
              predicates.add(cb.equal(issue.get("category"), issueCategory));
          }
          if (filters.getPostedDays() != null) {
              Date startDate = issueUtility.getStartDateForFilterIssues(filters.getPostedDays());
              predicates.add(cb.between(issue.get("createdAt"), startDate,new Date()));
          }
          if (filters.getLatitude() != null &amp;&amp; filters.getLongitude() != null) {
                // fetch by radius code comes here
          }
          cq.where(predicates.toArray(new Predicate[0]));```
  </code></pre>