2016-08-19 3 views
2

Google Datastore 데이터베이스를 백엔드 데이터베이스로 사용하고 Google에서 this 튜토리얼과 같은 지형 공간 쿼리를 사용하여 쿼리하려고하지만 모든 쿼리가 아무 것도 반환하지 않습니다.Datastore GeoSpatial 쿼리가 아무 것도 반환하지 않음

private static final String tableName = "DEBUG"; 
private static final double radius = 100 * 1000; //100 km 
private static final String NameKey = "Name"; 
private static final String LocationKey = "location"; 

//Parameters from the http servlet request 
String name; 
float lat, lng; 

//Insert a new person to the DB 

Entity person = new Entity(tableName); 
person.setProperty(NameKey, name); 
GeoPt location = new GeoPt(lat, lng); 
person.setProperty(LocationKey, location); 
datastore.put(person); 

//returns the users in the radius 

Query.Filter filter = new Query.StContainsFilter(LocationKey, new Query.GeoRegion.Circle(location, radius)); 
Query query = new Query(tableName).setFilter(filter); 

PreparedQuery pq = datastore.prepare(query); 

JsonArray users = new JsonArray(); 
for (Entity entity : pq.asIterable()){ 
    users.add(new JsonObject() 
     .add(NameKey, (String)entity.getProperty(NameKey)) 
     .add(LocationKey, ((GeoPt)entity.getProperty(LocationKey)).toString())); 
} 

result.add("Users", users); 
DB를에 삽입 작동

가, 여기에 구글 콘솔에서의 스크린 샷이다 : 나는 자바에서 다음 데모 디버깅 서블릿 만든

screenshot

그러나 쿼리가 항상 실패를하고 던졌습니다 :

코드에서 무엇이 잘못되었는지 알 수 없습니다. 나는 튜토리얼에로 복사, 나는 삽입 포인트 당신은 (/WEB_INF 폴더에) 당신의 datastore-indexes.xml 파일이 인덱스 정의를 추가 할 필요가

답변

1

(심지어 100km 반경을 닫고 불가) 매우 가깝습니다.

<?xml version="1.0" encoding="utf-8"?> 
<datastore-indexes 
    autoGenerate="true"> 

    <datastore-index kind="DEBUG" source="manual"> 
     <property name="location" mode="geospatial"/> 
    </datastore-index> 

</datastore-indexes> 

일반적으로 개발 서버에서 다른 쿼리를 시도하면 필요한 인덱스 정의가 자동으로 만들어집니다. 그러나 때로는 수동으로 추가해야 할 수도 있습니다. 백엔드 SRC 주요 자바 자원 웹 애플리케이션 WEB-INF 에서 appengine-web.xml을 logging.properties 웹 :

+0

나는 내 프로젝트 (안드로이드 스튜디오 IDE)에서, 나는이없는 것 같다. xml index.html 수동으로 추가해야합니까? 고마워요 :) –

+0

예, 추가하십시오. 샘플을 사용하여 답변을 업데이트하겠습니다. –

관련 문제