2016-08-19 8 views
2

私はGoogle Datastoreデータベースをバックエンドデータベースとして使用し、Googleがthisチュートリアルのような地理空間クエリを使用してクエリを実行しようとしていますが、すべてのクエリは何も返しません。私はJavaで次のデモのデバッグサーブレットを作っ: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への挿入は動作しますが、ここでは、Googleのコンソールからのスクリーンショットです:

screenshot

しかし、クエリは常に失敗し、スロー:

コードで何が間違っているのか分かりません。チュートリアルのようにコピーしました。挿入したポイントは非常に近いです(半径は100kmまで)

答えて

1

datastore-indexes.xmlファイル(/WEB_INFフォルダ)にこのインデックス定義を追加する必要があります。

<?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 メイン javaの リソース Webアプリケーション WEB-INF のappengine-web.xmlの logging.properties ウェブ:

+0

は、私は私のプロジェクト(AndroidのメーカーIDE)で、私は1つを持っていないようです。 xml index.html 手動で追加する必要がありますか? ありがとう:) –

+0

はい、それを追加します。答えをサンプルで更新します。 –

関連する問題