2015-05-06 89 views
1

您好我一直在關注這個教程http://googledevelopers.blogspot.com/2014/12/building-scalable-geofencing-api-on.html,這裏是我的問題,搜索JTS STR樹

我有經度和緯度座標的列表,我已經加入到一個JTS(Java的拓撲套件)STR樹作爲點。

現在我想發送一個形狀爲圓形的區域到STR樹來查找所有落在圓圈中的點。

Coordinate center = new Coordinate(entity.getLongitude(), entity.getLatitude()); 
    GeometricShapeFactory gsf = new GeometricShapeFactory(); 

    gsf.setCentre(center); 
    gsf.setNumPoints(20); 
    **gsf.setSize(320.0);** 
    Polygon poly = gsf.createCircle(); 
    Coordinate[] coordinates = poly.getCoordinates(); 


    //Create polygon from the coordinates. 
    GeometryFactory fact = new GeometryFactory(); 

    LinearRing linear_ring = new GeometryFactory().createLinearRing(coordinates); 

    Polygon polygon = new Polygon(linear_ring, null, fact); 

    List<STRLeaf> items = strTree.query(polygon.getEnvelopeInternal()); 

然而搜索的結果發回數據的所有中的經度和緯度點的樹。當我將圈的大小降低到320以下時,我沒有收到搜索STR樹的結果。有沒有人有這個理想的經驗,我想創建一個圈,找到~7miles圈內的所有點。

感謝您的時間

回答

1

事實證明,我在後端有一個愚蠢的錯誤。當我將這些物品添加到樹上時,我將x和y座標混合在一起,這樣Lat Long就被顛倒過來了。切換後,我現在可以將圓的大小設置爲0.1左右,並且效果很好。