Java 数据存储地理空间查询不返回任何内容

Java 数据存储地理空间查询不返回任何内容,java,google-app-engine,google-cloud-datastore,Java,Google App Engine,Google Cloud Datastore,我正在尝试使用Google数据存储数据库作为后端数据库,并使用Google教程中的地理空间查询对其进行查询,但所有查询都不会返回任何结果。我用Java制作了下一个调试servlet的演示: private static final String tableName = "DEBUG"; private static final double radius = 100 * 1000; //100 km private static final String NameKey = "Name"; pr

我正在尝试使用Google数据存储数据库作为后端数据库,并使用Google教程中的地理空间查询对其进行查询,但所有查询都不会返回任何结果。我用Java制作了下一个调试servlet的演示:

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控制台的屏幕截图:

但查询总是失败,并抛出:

javax.servlet.ServletContext log: DebugGeoPtServlet: Returns: {Error=no matching index found.
The suggested index for this query is:
    <datastore-index kind="DEBUG"  source="manual">
        <property name="location" mode="geospatial"/>
    </datastore-index>

}
javax.servlet.ServletContext日志:DebugGeoPtServlet:返回:{Error=未找到匹配的索引。
此查询的建议索引为:
}

我不知道代码中有什么错误。我在教程中复制了它,插入的点非常接近(甚至不接近100公里半径)

您需要将此索引定义添加到
数据存储index.xml
文件(在
/WEB\u 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>


通常,当您在开发服务器中尝试不同的查询时,它会自动创建必要的索引定义。但是,有时您可能需要手动添加它们。

我的项目(Android Studio IDE)中似乎没有:Backend src main java resources webapp WEB-INF appengine-WEB.xml logging.properties WEB.xml index.html我应该手动添加它吗?谢谢:)是的,添加它。我将用一个样本更新答案。