0
String loc_expr = "distance(location, geopoint(" + userLatitude + ", " + userLongitude + "))";
// Build the SortOptions
SortOptions sortOptions = SortOptions.newBuilder()
.addSortExpression(SortExpression.newBuilder().setExpression(loc_expr).setDirection(SortExpression.SortDirection.ASCENDING).setDefaultValueNumeric(0))
.setLimit(200).build();
// Build the QueryOptions
QueryOptions options = QueryOptions.newBuilder().addExpressionToReturn(FieldExpression.newBuilder().setExpression(loc_expr).setName("distance")).setLimit(limit)
.setCursor(cursor).setSortOptions(sortOptions).build();
String queryString = loc_expr + " < " + searchRadius * 1000;
// Build the Query and run the search
Query query = Query.newBuilder().setOptions(options).build(queryString);
IndexSpec indexSpec = IndexSpec.newBuilder().setName("restaurants").build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
Results<ScoredDocument> result = index.search(query);
if (result.getNumberFound() > 0) {
Collection<ScoredDocument> coll = result.getResults();
for (ScoredDocument sd : coll) {
Key<Restaurant> key = Key.create(String.valueOf(sd.getId()));
Restaurant rest = ofy().load().key(key).now();
Field f = sd.getExpressions().get(0);
log.info("distance in meter : " + f.getNumber());
}
}
인근 지역의 레스토랑을 찾으려면 위에 언급 된 코드를 사용하고 있습니다. 나의 관찰은 다음과 같습니다 -Google App Engine 검색 API의 거리 함수가 비정상적으로 작동합니다.
사례 1 : searchRadius = 0.5 km --- 거리의 최대 값 = 0.9 km
사례 2 : searchRadius = 1 km --- 거리의 최대 값 = 1.8 km
사례 3 : searchRadius은 = 2 km --- 거리의 최대 값 = 2.8 km
사례 4 : searchRadius = 3 km --- 거리의 최대 값 = 4.8 km
하는 이유는 무엇입니까 값의 반경이 더 지정된 거리?
참고 : - 본인이 직접 거리를 계산하지 않습니다. 거리가 검색 API에 의해 반환됩니다.