当前位置: 首页>>代码示例>>Java>>正文


Java GeoPt.getLongitude方法代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.GeoPt.getLongitude方法的典型用法代码示例。如果您正苦于以下问题:Java GeoPt.getLongitude方法的具体用法?Java GeoPt.getLongitude怎么用?Java GeoPt.getLongitude使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.appengine.api.datastore.GeoPt的用法示例。


在下文中一共展示了GeoPt.getLongitude方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:googlearchive,项目名称:MobileShoppingAssistant-sample,代码行数:32,代码来源:PlacesHelper.java

示例2: 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

示例3: getPlaces

import com.google.appengine.api.datastore.GeoPt; //导入方法依赖的package包/类
static List<PlaceInfo> getPlaces(GeoPt location, long distanceInMeters, int resultCount) {

    // TODO(user): Use memcache

    String geoPoint = "geopoint(" + location.getLatitude() + ", " + location.getLongitude() + ")";

    String query = "distance(place_location, " + geoPoint + ") < " + distanceInMeters;
    String locExpr = "distance(place_location, " + geoPoint + ")";

    SortExpression sortExpr = SortExpression.newBuilder()
        .setExpression(locExpr)
        .setDirection(SortExpression.SortDirection.ASCENDING)
        .setDefaultValueNumeric(distanceInMeters + 1)
        .build();
    Query searchQuery = Query.newBuilder().setOptions(QueryOptions.newBuilder()
        .setSortOptions(SortOptions.newBuilder().addSortExpression(sortExpr))).build(query);
    Results<ScoredDocument> results = getIndex().search(searchQuery);

    if (results.getNumberFound() == 0) {
      // geo-location doesn't work under dev_server
      if (environment.value() == Development) {
        // return all documents
        results = getIndex().search("value > 0");
      }
    }

    List<PlaceInfo> places = new ArrayList<PlaceInfo>();

    for (ScoredDocument document : results) {
      if (places.size() >= resultCount) {
        break;
      }

      GeoPoint p = document.getOnlyField("place_location").getGeoPoint();

      PlaceInfo place = new PlaceInfo();
      place.setplaceID(document.getOnlyField("id").getText());
      place.setName(document.getOnlyField("name").getText());
      place.setAddress(document.getOnlyField("address").getText());

      place.setLocation(new GeoPt((float) p.getLatitude(), (float) p.getLongitude()));

      // GeoPoints are not implemented on dev server and latitude and longitude are set to zero
      // But since those are doubles let's play safe
      // and use double comparison with epsilon set to 0.0001
      if (Math.abs(p.getLatitude()) <= 0.0001 && Math.abs(p.getLongitude()) <= 0.0001) {
        // set a fake distance of 5+ km
        place.setDistanceInKilometers(5 + places.size());
      } else {
        double distance = distanceInMeters / 1000;
        try {
          distance = getDistanceInKm(
              p.getLatitude(), p.getLongitude(), location.getLatitude(), location.getLongitude());
        } catch (Exception e) {
          log.warning("Exception when calculating a distance: " + e.getMessage());
        }

        place.setDistanceInKilometers(distance);
      }

      places.add(place);
    }

    return places;
  }
 
开发者ID:googlearchive,项目名称:solutions-mobile-shopping-assistant-backend-java,代码行数:66,代码来源:PlacesHelper.java

示例4: vectorBetween

import com.google.appengine.api.datastore.GeoPt; //导入方法依赖的package包/类
private static GeoPt vectorBetween(GeoPt a, Point b) {
	GeoPt res = new GeoPt(a.getLatitude()-b.getLatlon().getLatitude(),a.getLongitude()-b.getLatlon().getLongitude());
	return res;
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:5,代码来源:Utils.java

示例5: addLine

import com.google.appengine.api.datastore.GeoPt; //导入方法依赖的package包/类
private void addLine(String points) {
    	List<Point> pointsList = new ArrayList<Point>();
		String[] parts = points.split(Pattern.quote(","));
		Line l = null;
		if(parts[2].equals("bus")) {
			l = new Line(parts[0], parts[1], 1);
		} 
		HashSet<String> geoCells = new HashSet<String>();
		HashMap<String,Integer> directGeoCells = new HashMap<String,Integer>();
		HashMap<String,Boolean> ignoreCells = new HashMap<String,Boolean>();
		int start = 3; // felder 0,1,2 sind diese extradaten, ab feld 3 kommen die punkte
		for(int i = start; i<parts.length; i=i+3) {
			float a = Float.valueOf(parts[i]);
			float b = Float.valueOf(parts[i+1]);
			Point p = new Point(parts[i+2], a, b, null);
			com.beoui.geocell.model.Point _p1 = new com.beoui.geocell.model.Point(a,b);
			if(p.getStreet().substring(0, 4).equals("Au. ")) {
				p.setIgnore(true);
				geoCells.add(Utils.computeGeoCell(_p1));
			} else {
				geoCells.add(Utils.computeGeoCell(_p1));
			}
			/* i=2 and higher means that it is treating the second+ point
			   start creating interpolating points from here on
			   which means filling up the distance from the last point to the current (new) point
			   with many new points i.e. every 100m, unless type is not "bus" */
			if(i>=start+2) {
				Point lastPoint = pointsList.get(pointsList.size()-1);
				if(parts[2].equals("bus")) {
					GeoPt vector = Utils.vectorBetween(p, lastPoint);
					double distance = Utils.distanceApprox(vector.getLatitude(), vector.getLongitude());
					double distanceM = distance*Utils.distanceMultiplikator;
					long times = Math.round(distanceM/100.0);
//					Logger.getLogger(functionName).log(Level.INFO, functionName + ": Times: " + times);
//					System.err.println("lastPoint: " + lastPoint.getLatlon().getLatitude() + ", " + lastPoint.getLatlon().getLongitude());
					for(int j = 1; j<times; j++) {
						Point intermediate = new Point(lastPoint.getStreet(), (vector.getLatitude()/times)*j+lastPoint.getLatlon().getLatitude(),(vector.getLongitude()/times)*j+lastPoint.getLatlon().getLongitude(), false, true, null);
						com.beoui.geocell.model.Point _p2 = new com.beoui.geocell.model.Point(intermediate.getLatlon().getLatitude(),intermediate.getLatlon().getLongitude());
						String currentCell = Utils.computeGeoCell(_p2);
						intermediate.setIndex(pointsList.size());
						if(!lastPoint.isIgnore()) {
							pointsList.add(intermediate);
							geoCells.add(Utils.computeGeoCell(_p2));
							ignoreCells.put(currentCell, new Boolean(false));
						} else {
							geoCells.add(currentCell);
							if(!ignoreCells.containsKey(currentCell)) {
								ignoreCells.put(currentCell, new Boolean(true));
							}
						}
						directGeoCells.put(currentCell, intermediate.getIndex());
					}
				}
				lastPoint.setNextMainPointIndex(pointsList.size());
			}
			p.setIndex(pointsList.size());
			if(parts[2].equals("bus")) {
				directGeoCells.put(Utils.computeGeoCell(_p1),p.getIndex());
				if(!p.isIgnore()) {
					ignoreCells.put(Utils.computeGeoCell(_p1), new Boolean(false));
				} else {
					if(!ignoreCells.containsKey(Utils.computeGeoCell(_p1))) {
						ignoreCells.put(Utils.computeGeoCell(_p1), new Boolean(true));
					}
				}
			}
			pointsList.add(p);
		}
		Objectify ofy = Dao.getInstance().getObjectify();
		ManagementDao.getInstance().addLine(l, ofy);
		ManagementDao.getInstance().setPointsForLine(l, pointsList, ofy);
		ManagementDao.getInstance().addOrUpdatePlanQuadrats(geoCells, directGeoCells, l, ignoreCells, new HashMap<String,Boolean>(), true);
    }
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:74,代码来源:DatastoreTest.java

示例6: convertToGeoPoint

import com.google.appengine.api.datastore.GeoPt; //导入方法依赖的package包/类
public static GeoPoint convertToGeoPoint(GeoPt geoPt) {
    return new GeoPoint(geoPt.getLatitude(), geoPt.getLongitude());
}
 
开发者ID:openmash,项目名称:mashmesh,代码行数:4,代码来源:GeoUtils.java


注:本文中的com.google.appengine.api.datastore.GeoPt.getLongitude方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。