1

I have a table Restaurants which stores the details of restaurants including Latitude and Longitude .now i have to sort out the records from DB those within 20 Kilo Meter of the given Lat/Lon input values.

I am using RESTful web-service with hibernate.

Entity Class

@Entity
@Table(name = "restaurants")
public class Restaurants implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "restaurant_id")
    private int restaurantId;

    @Column(name = "restaurant_name")
    private String restaurantName;

    @Column(name = "category_id")
    private Integer categoryId;

    @Column(name = "image_url")
    private String imageUrl;

    private Float longitude;

    private Float latitude;

    @Column(name = "contact_name")
    private String contactName;

    @Column(name = "primary_phone")
    private String primaryPhone;

    @Column(name = "secondary_phone")
    private String secondaryPhone;

    private String fax;

    private String address1;

    private String address2;

    //Getters and Setters

} 

I have surfed but couldn't find any satisfying answer.is it preferable between operation to find out the difference between Lat/Long.or do i use Criteria ? Any one please provide me an answer .?

Stella
  • 1,817
  • 6
  • 30
  • 55

1 Answers1

0

Maybe you choose use Hibernate Spatial ?

You can find a tutorial here: http://www.hibernatespatial.org/documentation/02-Tutorial/01-tutorial4/

Becareful all database doesn't support Hibernate Spatial. You can check your database support here: http://www.hibernatespatial.org/documentation/03-dialects/01-overview/

Also becareful to change your SQLDialect

fabballe
  • 761
  • 4
  • 12
  • Do you use Hibernate Spatial or juste classic Hibernate ? – fabballe Aug 04 '15 at 10:00
  • Without Hibernate Spatial, I think you have to calculate max and min Latitude and Lontitude and make a where clause with this values. You can use java library to calculate your value like Java Geodesy Library for GPS (I never try it) – fabballe Aug 04 '15 at 11:38