2013-03-08 210 views
5

我正在使用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); 

現在的問題是我沒有從這裏得到任何結果。你能幫助我,因爲我沒有得到任何異常,只是得到空的名單。

+0

我不會相信自近期更新以來差不多兩年的事情。從來沒有玩過Java ..所以不要聽我的:) – Lipis 2013-03-08 13:05:49

+0

它的一個很好的問題,但你可能會得到更多的幫助在Python(我自己說吧) – 2013-03-10 14:29:54

回答

-2

我已經爲這種情況做了一個解決方法我添加了一個並行的JDO類來存儲和檢索地理空間結果。

+0

你可以請更新,你是如何做到這一點...這將從你身邊得到很大的幫助。 – 2013-07-17 22:02:57

+0

我面臨同樣的問題,但你的「答案」沒有提供任何解決方案。 – mdarwin 2014-03-12 05:31:11

+0

@mdarwin我已經解決了一個解決方案,我製作了一個JDO註釋類,它具有經緯度,並使用JDO持久化它們,因爲地理空間查詢可以很好地與JDO一起工作,所以我得到了結果。 – 2014-03-12 11:06:02