Class 用于将“GeoPoint”存储在 GCP 数据存储中 (Java)
Class for storing `GeoPoint` in GCP Datastore (Java)
我正在尝试通过 GCP Java 客户端库在数据存储中存储 geo_point
类型的数据。我想出了如何处理 Date
类型的数据,但无法得到我使用哪个 GeoPoint
class 的线索。
import com.google.datastore.v1.Entity;
import static com.google.datastore.v1.client.DatastoreHelper.makeValue;
import java.util.Date;
...
public class WriteToDatastoreFromTwitter {
private static Value dValue(Date k) {
return makeValue(k).setExcludeFromIndexes(true).build();
}
public static void main(String[] args) throws TwitterException {
final Builder builder = Entity.newBuilder().
setKey(key).
putProperties("timestamp", dValue(tweet.getCreatedAt()));
// How can I add a `geo_point` data?
我只是不确定我是否应该在 datastore
包之外使用 classes,例如:https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/search/GeoPoint
我自己想出来的。数据存储包的依赖包 com.google.type
中有 a class LatLng
,我可以使用它成功存储 geo_point
数据。以下是初始化对象的方法:
import com.google.type.LatLng;
...
LatLng x = LatLng.
newBuilder().
setLatitude(loc.getLatitude()).
setLongitude(loc.getLongitude()).
build();
在我的例子中,我通过
存储了它
private static Value gValue(LatLng k) {
return makeValue(k).setExcludeFromIndexes(true).build();
}
builder.putProperties("geo_point", gValue(x));
我正在尝试通过 GCP Java 客户端库在数据存储中存储 geo_point
类型的数据。我想出了如何处理 Date
类型的数据,但无法得到我使用哪个 GeoPoint
class 的线索。
import com.google.datastore.v1.Entity;
import static com.google.datastore.v1.client.DatastoreHelper.makeValue;
import java.util.Date;
...
public class WriteToDatastoreFromTwitter {
private static Value dValue(Date k) {
return makeValue(k).setExcludeFromIndexes(true).build();
}
public static void main(String[] args) throws TwitterException {
final Builder builder = Entity.newBuilder().
setKey(key).
putProperties("timestamp", dValue(tweet.getCreatedAt()));
// How can I add a `geo_point` data?
我只是不确定我是否应该在 datastore
包之外使用 classes,例如:https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/search/GeoPoint
我自己想出来的。数据存储包的依赖包 com.google.type
中有 a class LatLng
,我可以使用它成功存储 geo_point
数据。以下是初始化对象的方法:
import com.google.type.LatLng;
...
LatLng x = LatLng.
newBuilder().
setLatitude(loc.getLatitude()).
setLongitude(loc.getLongitude()).
build();
在我的例子中,我通过
存储了它private static Value gValue(LatLng k) {
return makeValue(k).setExcludeFromIndexes(true).build();
}
builder.putProperties("geo_point", gValue(x));