Google cloud platform 用于在GCP数据存储(Java)中存储“GeoPoint”的类
我正试图通过GCP Java客户端库在数据存储中存储Google cloud platform 用于在GCP数据存储(Java)中存储“GeoPoint”的类,google-cloud-platform,google-cloud-datastore,geopoints,Google Cloud Platform,Google Cloud Datastore,Geopoints,我正试图通过GCP Java客户端库在数据存储中存储geo_point类型数据。我知道了如何处理日期类型的数据,但无法得到我用于此的地质点类的线索 import com.google.datastore.v1.Entity; import static com.google.datastore.v1.client.DatastoreHelper.makeValue; import java.util.Date; ... public class WriteToDatastoreFromTwi
geo_point
类型数据。我知道了如何处理日期
类型的数据,但无法得到我用于此的地质点
类的线索
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?
我只是不确定是否应该使用
数据存储
包之外的类,比如:我自己想出来的。有一个依赖包com.google.type
到数据存储包,我可以使用它成功地存储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));