本文整理汇总了Java中com.google.appengine.api.datastore.GeoPt类的典型用法代码示例。如果您正苦于以下问题:Java GeoPt类的具体用法?Java GeoPt怎么用?Java GeoPt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeoPt类属于com.google.appengine.api.datastore包,在下文中一共展示了GeoPt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildDocument
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
/**
* Builds a new Place document to insert in the Places index.
* @param placeId the identifier of the place in the database.
* @param placeName the name of the place.
* @param placeAddress the address of the place.
* @param location the GPS location of the place, as a GeoPt.
* @return the Place document created.
*/
public static Document buildDocument(
final Long placeId, final String placeName,
final String placeAddress, final GeoPt location) {
GeoPoint geoPoint = new GeoPoint(location.getLatitude(),
location.getLongitude());
Document.Builder builder = Document.newBuilder()
.addField(Field.newBuilder().setName("id")
.setText(placeId.toString()))
.addField(Field.newBuilder().setName("name").setText(placeName))
.addField(Field.newBuilder().setName("address")
.setText(placeAddress))
.addField(Field.newBuilder().setName("place_location")
.setGeoPoint(geoPoint));
// geo-location doesn't work under dev_server, so let's add another
// field to use for retrieving documents
if (environment.value() == Development) {
builder.addField(Field.newBuilder().setName("value").setNumber(1));
}
return builder.build();
}
示例2: getTrainConnections
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
public SearchResultProxy getTrainConnections(float lat1, float lon1, float lat2, float lon2, boolean ignoreTrains, boolean ignoreSubte) throws IllegalArgumentException {
QuotaService qs = QuotaServiceFactory.getQuotaService();
long start = qs.getCpuTimeInMegaCycles();
Dao.getInstance();
Objectify ofy = ObjectifyService.begin();
String functionName = "getTrainConnections";
HashSet<Key<Line>> tabuTrainsSet = new HashSet<Key<Line>>();
if(ignoreTrains) {
tabuTrainsSet.addAll(Dao.getTrainKeys());
}
if(ignoreSubte) {
tabuTrainsSet.addAll(Dao.getSubteKeys());
}
ConnectionProxy connTren = Dao.getInstance().indirectSearch(new GeoPt(lat1, lon1), new GeoPt(lat2, lon2), tabuTrainsSet, new HashSet<Key<Line>>(), ofy);
List<ConnectionProxy> conns = new LinkedList<ConnectionProxy>();
conns.add(connTren);
long end = qs.getCpuTimeInMegaCycles();
double cpuSeconds = qs.convertMegacyclesToCpuSeconds(end - start);
Logger.getLogger("LineListServiceImpl").log(Level.INFO, functionName + ": " + cpuSeconds + " CPU seconds.");
if(connTren != null) {
return new SearchResultProxy(conns, null, null);
} else {
return null;
}
}
示例3: closestPoint
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
public static Point closestPoint(GeoPt thePoint, Collection<Point> points) {
GeoPt p = thePoint;
double dMin = 99999999.9;
Point pMin = null;
for(Point pCur : points) {
double distCur = Utils.distanceApprox(p, pCur);
if(pCur.isIgnore()) { // absolutely avoid points that are set as ignore. Related to the dirty hack that searches any point, if none were found that are not "ignore"-flagged. Theoretically there shouldn't be any case where this is necessary, but right now there is (rarely).
distCur += 10000;
}
if(distCur < dMin) {
dMin = distCur;
pMin = pCur;
}
}
return pMin;
}
示例4: getPlacesByProximity
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
public static List<Place> getPlacesByProximity(GeoPt origin, Double proximityMeters, int count){
List<Place> places = new ArrayList<Place>();
//hmmm... inequality filters are limited to one operation
// this would be expensive on a large DB...
List<Place> results = new ArrayList<Place>();
places.addAll(ofy().load().type(Place.class).limit(count).list());
for(Place p : places) {
GeoPt placeLocation =
new GeoPt(p.getLatitude().floatValue(), p.getLongitude().floatValue());
double distance = PlaceUtil.getDistanceInMeters(origin,placeLocation);
if(distance <= proximityMeters){
// covert distance to string and pack into payload for device
double distanceMiles = distance * metersToMiles;
String distanceStr = String.format("%.2f", distanceMiles);
p.setDistance(distanceStr + " miles");
results.add(p);
}
}
return results;
}
示例5: listPlaces
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
/**
* Return a collection of registered devices
*
* @param count The number of devices to list
* @param userLongitude The coordinate of user device
* @param userLatitude The coordinate of user deivce
* @param radiusInMeters Proximity to search
* @return a list of Google Cloud Messaging registration Ids
*/
@ApiMethod(name = "listPlaces")
public Collection<Place> listPlaces(@Named("count") int count,
@Named("longitude") Double userLongitude, @Named("latitude") Double userLatitude,
@Named("range") Double radiusInMeters) {
DataInjector injector = new DataInjector();
injector.createDataSet();
// Convert Strings into floats
float longitude, latitude;
longitude = userLongitude.floatValue();
latitude = userLatitude.floatValue();
GeoPt location = new GeoPt(latitude, longitude);
List<Place> places = PlaceUtil.getPlacesByProximity(location,radiusInMeters,count);
log.info(places.size() + " places returned ");
return places;
//return CollectionResponse.<Place>builder().setItems(places).build();
}
示例6: addData
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
@Before
public void addData() throws InterruptedException {
Query query = new Query(kindName, rootKey);
if (service.prepare(query).countEntities(fetchOption) == 0) {
List<Entity> elist = new ArrayList<Entity>();
for (int i = 0; i < count; i++) {
Entity newRec = new Entity(kindName, rootKey);
newRec.setProperty("stringData", "string test data " + i);
newRec.setProperty("intData", 10 * i);
newRec.setProperty("stringList", Arrays.asList("abc" + i, "xyz" + i, "abc" + i));
newRec.setProperty("intList", Arrays.asList(i, 50 + i, 90 + i));
newRec.setProperty("timestamp", new Date());
newRec.setProperty("floatData", new Float(i + 0.1));
newRec.setProperty("ratingData", new Rating(i + 20));
newRec.setProperty("booleanData", true);
newRec.setProperty("geoptData", new GeoPt((float) (i * 20 - 90), new Float(i * 30 - 179.1)));
newRec.setProperty("byteStrProp", new ShortBlob(("shortblob" + (i * 30)).getBytes()));
elist.add(newRec);
}
service.put(elist);
sync(waitTime);
}
}
示例7: testWithPropertyProjection
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
@Test
public void testWithPropertyProjection() {
Query query = new Query(kindName, rootKey);
query.addProjection(new PropertyProjection("geoptData", GeoPt.class));
Filter filter1 = Query.CompositeFilterOperator.or(
Query.FilterOperator.LESS_THAN.of("intList", 5),
Query.FilterOperator.GREATER_THAN.of("intList", 90));
Filter filter2 = Query.FilterOperator.EQUAL.of("intList", 52);
query.setFilter(Query.CompositeFilterOperator.and(filter1, filter2));
// sql statement
String sql = "SELECT geoptData FROM " + kindName;
sql += " WHERE ((intList < 5 or intList > 90) AND intList = 52)";
sql += " AND __ancestor__ is " + rootKey;
assertEquals(sql.toLowerCase(), query.toString().toLowerCase());
// check query result
List<Entity> results = service.prepare(query).asList(fo);
Assert.assertTrue(results.size() > 0);
assertEquals(new GeoPt((float) (2.12), (float) (2.98)), results.get(0).getProperty("geoptData"));
for (Entity e : results) {
assertEquals(1, e.getProperties().size());
assertTrue(e.getProperties().containsKey("geoptData"));
}
}
示例8: buildDocument
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
static Document buildDocument(
String placeId, String placeName, String placeAddress, GeoPt location) {
GeoPoint geoPoint = new GeoPoint(location.getLatitude(), location.getLongitude());
Document.Builder builder = Document.newBuilder()
.addField(Field.newBuilder().setName("id").setText(placeId))
.addField(Field.newBuilder().setName("name").setText(placeName))
.addField(Field.newBuilder().setName("address").setText(placeAddress))
.addField(Field.newBuilder().setName("place_location").setGeoPoint(geoPoint));
// geo-location doesn't work under dev_server, so let's add another
// field to use for retrieving documents
if (environment.value() == Development) {
builder.addField(Field.newBuilder().setName("value").setNumber(1));
}
Document place = builder.build();
return place;
}
开发者ID:googlearchive,项目名称:solutions-mobile-shopping-assistant-backend-java,代码行数:21,代码来源:PlacesHelper.java
示例9: testComplexRow
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
@Test
public void testComplexRow() throws IOException {
Table table = new Table().setColumns(Arrays.asList(
new Column().setName("first").setType("LOCATION"),
new Column().setName("second").setType("STRING"),
new Column().setName("third").setType("STRING"),
new Column().setName("fourth").setType("DATETIME")
));
FusionTableContentWriter writer = new FusionTableContentWriter(table);
DateTime dateTime = DateTime.parse("2013-05-22T11:00:00-03:00");
writer.writeRecord(new GeoPt(44.990288f, -64.131035f), "a string", "another string", dateTime);
Assert.assertEquals(
"\"first\",\"second\",\"third\",\"fourth\"\n" +
"\"44.990288 -64.131035\",\"a string\",\"another string\",\"2013-05-22T11:00:00-03:00\"\n",
getOutputString(writer)
);
}
示例10: testGeoptEncoding
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
@Test
public void testGeoptEncoding() throws IOException {
Table table = new Table().setColumns(Arrays.asList(
new Column().setName("name").setType("STRING"),
new Column().setName("location").setType("LOCATION")
));
FusionTableContentWriter writer = new FusionTableContentWriter(table);
writer.writeRecord("John Smith", new GeoPt(40.767838f, -73.981972f));
writer.writeRecord("Jane Adams", new GeoPt(44.990288f, -64.131035f));
writer.writeRecord("Bob Mcconnell", new GeoPt(46.099918f, -60.754677f));
Assert.assertEquals(
"\"name\",\"location\"\n" +
"\"John Smith\",\"40.767838 -73.981972\"\n" +
"\"Jane Adams\",\"44.990288 -64.131035\"\n" +
"\"Bob Mcconnell\",\"46.099918 -60.754677\"\n",
getOutputString(writer)
);
}
示例11: getAddress
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
private Address getAddress(@Nullable Location fbLocation) {
if (fbLocation == null) {
return null;
}
Address address = new Address();
address.setStreet(fbLocation.getStreet());
address.setCity(fbLocation.getCity());
address.setState(fbLocation.getState());
address.setCountry(fbLocation.getCountry());
address.setZip(fbLocation.getZip());
if ((fbLocation.getLatitude() != null) && (fbLocation.getLongitude() != null)) {
address.setGeoPt(GeoPtWrapper.create(
new GeoPt(fbLocation.getLatitude().floatValue(), fbLocation.getLongitude().floatValue())));
}
return address;
}
示例12: getGeoPt
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
@Nullable
public static GeoPt getGeoPt(String addressStr) {
// TODO(avaliani): use an api key to avoid geocoding quota limits
final Geocoder geocoder = new Geocoder();
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder()
.setAddress(addressStr)
.setLanguage("en")
.getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
if (geocoderResponse.getStatus() == GeocoderStatus.OK) {
GeocoderResult firstResult = geocoderResponse.getResults().get(0);
return new GeoPt(
firstResult.getGeometry().getLocation().getLat().floatValue(),
firstResult.getGeometry().getLocation().getLng().floatValue());
} else {
log.log(GEOCODE_LOG_LEVEL,
"Geocoding failed: status=" + geocoderResponse.getStatus() + ", " +
"response=" + geocoderResponse);
// TODO(avaliani): Properly handle geopt encoding failures. Retrying in cases where
// the error is over quota.
return null;
}
}
示例13: defaultIndexTypeLookup
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
public static IndexTypeLookup defaultIndexTypeLookup() {
IndexTypeLookup indexTypeLookup = new IndexTypeLookup();
indexTypeLookup.addMapping(Key.class, IndexType.Identifier);
indexTypeLookup.addMapping(com.google.appengine.api.datastore.Key.class, IndexType.Identifier);
indexTypeLookup.addMapping(GeoPt.class, IndexType.GeoPoint);
return indexTypeLookup;
}
示例14: shouldCreateGeoPointFromGeoPt
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
@Test
public void shouldCreateGeoPointFromGeoPt() {
GeoPoint geoPoint = new GeoPoint(1.23, 4.56);
GeoPt result = transformer.from(geoPoint);
assertThat(result.getLatitude(), is(1.23f));
assertThat(result.getLongitude(), is(4.56f));
}
示例15: shouldCreateGeoPointFromGeoPt
import com.google.appengine.api.datastore.GeoPt; //导入依赖的package包/类
@Test
public void shouldCreateGeoPointFromGeoPt() {
GeoPt geoPt = new GeoPt(1.23f, 4.56f);
GeoPoint result = transformer.from(geoPt);
assertThat(result.getLatitude(), is((double) 1.23f));
assertThat(result.getLongitude(), is((double) 4.56f));
}