Android 修改endpoint类以列出存储在App Engine数据存储中的附近位置,而不是所有位置
我刚开始从谷歌那里了解云端点。本教程中提供的示例应用程序将Place定义为一个JPA实体,该实体具有一个GeoPt字段,用于存储其在应用程序引擎后端应用程序中的位置,android客户端可以通过Google云端点访问该应用程序 我想修改这个示例应用程序中的PlaceEndPoint类,以仅返回存储在数据存储中靠近Android应用程序用户的位置的列表,而不是列出数据存储中的所有位置。我所说的“附近”,是指那些位于半径约30公里范围内的地方的列表,按与用户的距离排序。稍后,我需要根据用户希望看到的位置类型对这些结果应用更多过滤器 为此,我可能必须: 1.将用户的位置从android客户端传递到应用引擎后端 2.调整后端应用程序PlaceEndpoint类中的函数listPlace,以返回用户附近的位置 但我对appengine和端点还不够熟悉,不知道该怎么做。请给我任何有帮助的提示或指导。非常感谢您的期待 以下是包含在Google示例应用程序中的PlaceEndpoint类中listPlace方法的代码:Android 修改endpoint类以列出存储在App Engine数据存储中的附近位置,而不是所有位置,android,google-app-engine,geolocation,google-cloud-datastore,google-cloud-endpoints,Android,Google App Engine,Geolocation,Google Cloud Datastore,Google Cloud Endpoints,我刚开始从谷歌那里了解云端点。本教程中提供的示例应用程序将Place定义为一个JPA实体,该实体具有一个GeoPt字段,用于存储其在应用程序引擎后端应用程序中的位置,android客户端可以通过Google云端点访问该应用程序 我想修改这个示例应用程序中的PlaceEndPoint类,以仅返回存储在数据存储中靠近Android应用程序用户的位置的列表,而不是列出数据存储中的所有位置。我所说的“附近”,是指那些位于半径约30公里范围内的地方的列表,按与用户的距离排序。稍后,我需要根据用户希望看到的
@Api(name = "placeendpoint", namespace = @ApiNamespace(ownerDomain = "google.com", ownerName = "google.com", packagePath = "samplesolutions.mobileassistant"))
public class PlaceEndpoint {
/**
* This method lists all the entities inserted in datastore.
* It uses HTTP GET method and paging support.
*
* @return A CollectionResponse class containing the list of all entities
* persisted and a cursor to the next page.
*/
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listPlace")
public CollectionResponse<Place> listPlace(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit) {
EntityManager mgr = null;
Cursor cursor = null;
List<Place> execute = null;
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select from Place as Place");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<Place>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
// Tight loop for fetching all entities from datastore and accomodate
// for lazy fetch.
for (Place obj : execute)
;
} finally {
mgr.close();
}
return CollectionResponse.<Place> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
你试过什么?Place类的外观如何,尤其是要基于距离计算的字段?什么是附近,几英尺/米,一座城市,一个星球?张贴100多行未经修改的示例代码一点帮助都没有。你好,Philipp,感谢您的回复!我已经修改了原来的帖子,尽我所能解释你所要求的内容。如果我能提供更多有用的信息,请告诉我。如果您调用本地方法而不是远程服务,查询附近位置的Java方法签名是什么?如果有,请添加所需的@Api。。。注释应该简单明了。