0

In the following code I fetch the latitude and longitude from Database using RiderLocationRepository Now I want to return not only the distance but also latitude longitude and rider_id , I saw Different solutions But I cant understand that how can I do it

Can anybody solve this problem ?

RiderService

@Component
public class RiderService {
    @Autowired RiderLocationRepository riderLocationRepository;
    public List Location(Double lattitude,Double longitude)
    {
        RiderLocation rl = null;
         List <Double> distance=new ArrayList<>(); 
         List<RiderLocation> allRidersLocation  = riderLocationRepository.findAll();
          for (RiderLocation riderLocation : allRidersLocation) {
            Double oneRiderDist=distFrom(riderLocation.getLatitude(), riderLocation.getLongitude(), lattitude, longitude);
            distance.add(oneRiderDist);
          }   
            return distance;     
    }

RiderLocation.java

@Entity
public class RiderLocation implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @ManyToOne
    private User rider;
    private Double latitude;
    private Double longitude;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public User getRider() {
        return rider;
    }

    public void setRider(User rider) {
        this.rider = rider;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }
}
maria salahuddin
  • 125
  • 2
  • 3
  • 16

0 Answers0