私は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のコンソールからのスクリーンショットです:
しかし、クエリは常に失敗し、スロー:
コードで何が間違っているのか分かりません。チュートリアルのようにコピーしました。挿入したポイントは非常に近いです(半径は100kmまで)
は、私は私のプロジェクト(AndroidのメーカーIDE)で、私は1つを持っていないようです。 xml index.html 手動で追加する必要がありますか? ありがとう:) –
はい、それを追加します。答えをサンプルで更新します。 –