gpt4 book ai didi

Java 检查 1 公里圆内是否有长纬度

转载 作者:可可西里 更新时间:2023-11-01 07:44:15 28 4
gpt4 key购买 nike

<分区>

我正在开发一个 Java EE 项目,它具有这样的实体:

@Entity
public class Location {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long messageId;

@ManyToOne
private User user;

private String name;

private Float latitude;

private Float longitude;
}

如果这些位置在 1 公里直径的圆内,我需要用中心点过滤这些位置。

enter image description here

我需要这样的方法,只返回 A、B、C、E 位置。

public List<Location> findLocations(Float longitude, Float latitude) {
List<Location> locations =
entityManager.createQuery("select l from Location where ???")
.setParameter("longitude", longitude)
.setParameter("latitude", latitude)
.getResultList();
return locations;
}

我找到了一些代码示例,但我必须遍历 db 上的所有位置(这将非常昂贵)

我可以直接用 createQuery() 做吗?

Note: I'm using MySQL

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com