gpt4 book ai didi

java - 使用 Objectify 进行地理空间半径搜索

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:42 25 4
gpt4 key购买 nike

我正在使用 GeoModel 开发应用程序.我需要根据给定的纬度和经度在特定半径内执行搜索。我能够使用 Objectify 在数据存储中生成 GeoCell,但无法取回特定半径内的结果。

我在下面分享我的代码。

实体类

@Entity
public class NewsFeed implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Index
private Long feedID;
@Index
private String topic;
@Index
private String title;
private String description;
@Index
private Date createDate;
private String imageOrVideo;
private String imageUrl;
private String blobKey;
@Latitude
private Double latitude;
@Longitude
private Double longitude;
@Geocells
private List<String> cells;

// getter and setters ...
}

自定义 GeocellQueryEngine 类 From This Source

public class ObjectifyGeocellQueryEngine implements GeocellQueryEngine {
private String geocellsProperty;
private Objectify ofy;
public static final String DEFAULT_GEOCELLS_PROPERTY = "cells";

public ObjectifyGeocellQueryEngine(Objectify ofy) {
this(ofy, DEFAULT_GEOCELLS_PROPERTY);
}

public ObjectifyGeocellQueryEngine(Objectify ofy, String geocellsProperty) {
this.ofy = ofy;
this.geocellsProperty = geocellsProperty;
}

@Override
public <T> List<T> query(GeocellQuery baseQuery, List<String> geocells, Class<T> entityClass) {
StringTokenizer st;
int tokenNo = 0;
Query<T> query = ofy.query(entityClass);
if (baseQuery != null) {
st = new StringTokenizer(baseQuery.getBaseQuery(), ",");
while (st.hasMoreTokens()) {
query.filter(st.nextToken(), baseQuery.getParameters().get(tokenNo++));
}
}
return query.filter(geocellsProperty + " IN", geocells).list();
}
}

在此处获取数据

    Point p = new Point(24.8993714, 79.5839124);
// Generates the list of GeoCells
List<String> cells = GeocellManager.generateGeoCell(p);
List<Object> params = new ArrayList<Object>();
params.add("Movies");
GeocellQuery baseQuery = new GeocellQuery("topic == topic", "String topic",params);
ObjectifyGeocellQueryEngine objectifyGeocellQueryEngine = new ObjectifyGeocellQueryEngine(ofy(), "cells");
List<NewsFeed> list = objectifyGeocellQueryEngine.query(baseQuery, cells, NewsFeed.class);
List<NewsFeed> list2 = GeocellManager.proximitySearch(p, 10, 10000,NewsFeed.class, baseQuery, objectifyGeocellQueryEngine, GeocellManager.MAX_GEOCELL_RESOLUTION);
System.out.println(list+" : "+list2);

现在的问题是我没有从这里得到任何结果。你们能不能帮我解决这个问题,因为我没有得到任何异常,只是得到空列表。

最佳答案

我已经针对这种情况做了一个解决方法,我添加了一个并行 JDO 类来存储和检索地理空间结果。

关于java - 使用 Objectify 进行地理空间半径搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15292834/

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