本文整理匯總了Java中com.google.cloud.datastore.LatLng類的典型用法代碼示例。如果您正苦於以下問題:Java LatLng類的具體用法?Java LatLng怎麽用?Java LatLng使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LatLng類屬於com.google.cloud.datastore包,在下文中一共展示了LatLng類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toDatastore
import com.google.cloud.datastore.LatLng; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
if (input == null) {
return NullValue.newBuilder();
}
GeoLocation geoLocation = (GeoLocation) input;
return LatLngValue.newBuilder(LatLng.of(geoLocation.getLatitude(), geoLocation.getLongitude()));
}
示例2: toModel
import com.google.cloud.datastore.LatLng; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
if (input instanceof NullValue) {
return null;
}
LatLngValue value = (LatLngValue) input;
LatLng coordinates = value.get();
return new GeoLocation(coordinates.getLatitude(), coordinates.getLongitude());
}
示例3: toDatastore
import com.google.cloud.datastore.LatLng; //導入依賴的package包/類
@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
ValueBuilder<?, ?, ?> builder;
if (input == null) {
builder = NullValue.newBuilder();
} else if (input instanceof Long) {
builder = LongValue.newBuilder((long) input);
} else if (input instanceof Double) {
builder = DoubleValue.newBuilder((double) input);
} else if (input instanceof Boolean) {
builder = BooleanValue.newBuilder((boolean) input);
} else if (input instanceof String) {
builder = StringValue.newBuilder((String) input);
} else if (input instanceof DatastoreKey) {
builder = KeyValue.newBuilder(((DatastoreKey) input).nativeKey());
} else if (input instanceof GeoLocation) {
GeoLocation geoLocation = (GeoLocation) input;
builder = LatLngValue
.newBuilder(LatLng.of(geoLocation.getLatitude(), geoLocation.getLongitude()));
} else if (input instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, ?> map = (Map<String, ?>) input;
FullEntity.Builder<IncompleteKey> entityBuilder = FullEntity.newBuilder();
for (Map.Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
entityBuilder.set(key, toDatastore(entry.getValue()).build());
}
builder = EntityValue.newBuilder(entityBuilder.build());
} else {
throw new MappingException(String.format("Unsupported type: %s", input.getClass().getName()));
}
return builder;
}
示例4: toModel
import com.google.cloud.datastore.LatLng; //導入依賴的package包/類
@Override
public Object toModel(Value<?> input) {
Object javaValue;
if (input instanceof NullValue) {
javaValue = null;
} else if (input instanceof StringValue) {
javaValue = input.get();
} else if (input instanceof LongValue) {
javaValue = input.get();
} else if (input instanceof DoubleValue) {
javaValue = input.get();
} else if (input instanceof BooleanValue) {
javaValue = input.get();
} else if (input instanceof KeyValue) {
javaValue = new DefaultDatastoreKey(((KeyValue) input).get());
} else if (input instanceof LatLngValue) {
LatLng latLong = ((LatLngValue) input).get();
javaValue = new GeoLocation(latLong.getLatitude(), latLong.getLongitude());
} else if (input instanceof EntityValue) {
EntityValue entityValue = (EntityValue) input;
FullEntity<?> entity = entityValue.get();
Map<String, Object> map = new HashMap<>();
for (String property : entity.getNames()) {
map.put(property, toModel(entity.getValue(property)));
}
javaValue = map;
} else {
throw new MappingException(String.format("Unsupported type %s", input.getClass().getName()));
}
return javaValue;
}