6

GeoModelを使用してアプリケーションを開発しています。指定された緯度と経度に基づいて、特定の半径で検索を実行する必要があります。Objectify を使用してデータストアに GeoCells を生成することはできますが、特定の半径で結果を取得することはできません。

以下のコードを共有しています。

エンティティ クラス

@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 クラス

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);

問題は、ここから結果が得られないことです。例外はなく、空のリストを取得しているだけなので、これを手伝ってもらえますか。

4

1 に答える 1

-2

この状況の回避策を実行し、地理空間結果を保存および取得するための並列JDOクラスを追加しました。

于 2013-03-18T10:59:43.237 に答える