private static int compareGeoPoints(Value left, Value right) { int cmp = Double.compare( left.getGeoPointValue().getLatitude(), right.getGeoPointValue().getLatitude()); if (cmp != 0) { return cmp; } else { return Double.compare( left.getGeoPointValue().getLongitude(), right.getGeoPointValue().getLongitude()); } }
@Override protected LatLng getValue(com.google.datastore.v1.Value from) { return new LatLng( from.getGeoPointValue().getLatitude(), from.getGeoPointValue().getLongitude()); }
case GEO_POINT_VALUE: return new GeoPoint( v.getGeoPointValue().getLatitude(), v.getGeoPointValue().getLongitude()); case ARRAY_VALUE: List<Object> list = new ArrayList<>();
west = loc.getLongitude(); east = loc.getLongitude(); if (loc.getLongitude() < west) west = loc.getLongitude(); else if (loc.getLongitude() > east) east = loc.getLongitude();
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng point) { mMap.addMarker(new MarkerOptions() .snippet("Lat: " + point.getLatitude() + ", Lng: " + point.getLongitude()) .position(point) .title("You are here!") .flat(true) .draggable(true)); } });
@Override public void onMapLongClick(LatLng point) { Latitude lat = point.getLatitude(); Longitude lng = point.getLongitude(); }
// Make sure you are using marker views so you can update the rotation. marker.setRotation((float) computeHeading(marker.getPosition(), position)); ... public static double computeHeading(LatLng from, LatLng to) { // Compute bearing/heading using Turf and return the value. return TurfMeasurement.bearing( Position.fromCoordinates(from.getLongitude(), from.getLatitude()), Position.fromCoordinates(to.getLongitude(), to.getLatitude()) ); }
public void addToPref(LatLng location){//I'm supposing you are using LatLang class String aLocation = location.getLatitude() + "," + location.getLongitude(); //and save to shared preference }
// Returns the heading from one LatLng to another LatLng. Headings are. Expressed in degrees // clockwise from North within the range [-180,180). The math for this method came from // http://williams.best.vwh.net/avform.htm#Crs I only converted it to Java. public static double computeHeading(LatLng from, LatLng to) { double fromLat = Math.toRadians(from.getLatitude()); double fromLng = Math.toRadians(from.getLongitude()); double toLat = Math.toRadians(to.getLatitude()); double toLng = Math.toRadians(to.getLongitude()); double dLng = toLng - fromLng; double heading = Math.atan2(Math.sin(dLng) * Math.cos(toLat), Math.cos(fromLat) * Math.sin(toLat) - Math.sin(fromLat) * Math.cos(toLat) * Math.cos(dLng)); return (Math.toDegrees(heading) >= -180 && Math.toDegrees(heading) < 180) ? Math.toDegrees(heading) : ((((Math.toDegrees(heading) + 180) % 360) + 360) % 360 + -180); }
for(//for loop){ LatLng point = new LatLng(lat,lng) if(point.getLatitude() > maxLat){ maxLat = point.getLatitude(); } if(point.getLatitude() < minLat){ minLat = point.getLatitude(); } if(point.getLongitude() > maxLon){ maxLon = point.getLongitude(); } if(point.getLongitude() < minLon){ minLon = point.getLongitude(); } } northEast = new LatLng(maxLat,maxLon); southWest = new LatLng(minLat,minLon);
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.type.LatLng)) { return super.equals(obj); } com.google.type.LatLng other = (com.google.type.LatLng) obj; boolean result = true; result = result && ( java.lang.Double.doubleToLongBits(getLatitude()) == java.lang.Double.doubleToLongBits( other.getLatitude())); result = result && ( java.lang.Double.doubleToLongBits(getLongitude()) == java.lang.Double.doubleToLongBits( other.getLongitude())); return result; }
/** * <p> * Calculate the end point of traveling along a great-circle path from a * given starting point with a given intitial bearing for a known distance. * </p> * * @param start * the starting point. * @param initialBearing * the initial bearing. * @param distance * the distance to travel. * @param unit * the unit in which distance is measured. * @return the end point. */ public static LatLng travel(LatLng start, double initialBearing, double distance, LengthUnit unit) { double bR = Math.toRadians(initialBearing); double lat1R = Math.toRadians(start.getLatitude()); double lon1R = Math.toRadians(start.getLongitude()); double dR = distance / LatLngConfig.getEarthRadius(unit); double a = Math.sin(dR) * Math.cos(lat1R); double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a * Math.cos(bR)); double lon2 = lon1R + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R) * Math.sin(lat2)); return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2)); }
/** * <p> * Calculate the end point of traveling along a great-circle path from a * given starting point with a given intitial bearing for a known distance. * </p> * * @param start * the starting point. * @param initialBearing * the initial bearing. * @param distance * the distance to travel. * @param unit * the unit in which distance is measured. * @return the end point. */ public static LatLng travel(LatLng start, double initialBearing, double distance, LengthUnit unit) { double bR = Math.toRadians(initialBearing); double lat1R = Math.toRadians(start.getLatitude()); double lon1R = Math.toRadians(start.getLongitude()); double dR = distance / LatLngConfig.getEarthRadius(unit); double a = Math.sin(dR) * Math.cos(lat1R); double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a * Math.cos(bR)); double lon2 = lon1R + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R) * Math.sin(lat2)); return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2)); }
public synchronized void onSuccess(LatLng point) { gotCoords = true; coords = new LonLat(point.getLongitude(), point.getLatitude()); notify();
public boolean pointInCircle(Circle c, LatLng coord) { Rectangle r = c.getBounds(); double rectX = r.getX(); double rectY = r.getY(); double rectWidth = r.getWidth(); double rectHeight = r.getHeight(); double circleCenterX = rectX + rectWidth/2; double circleCenterY = rectY + rectHeight/2; double lat = coord.getLatitude(); double lon = coord.getLongitude(); // Point in circle if (x−h)^2 + (y−k)^2 <= r^2 double rSquared = Math.pow(rectWidth/2, 2); double point = Math.pow(lat - circleCenterX, 2) + Math.pow(lon - circleCenterY, 2); return (point <= rSquared) ? true : false; }
private static int compareGeoPoints(Value left, Value right) { int cmp = Double.compare( left.getGeoPointValue().getLatitude(), right.getGeoPointValue().getLatitude()); if (cmp != 0) { return cmp; } else { return Double.compare( left.getGeoPointValue().getLongitude(), right.getGeoPointValue().getLongitude()); } }
public Builder mergeFrom(com.google.type.LatLng other) { if (other == com.google.type.LatLng.getDefaultInstance()) return this; if (other.getLatitude() != 0D) { setLatitude(other.getLatitude()); } if (other.getLongitude() != 0D) { setLongitude(other.getLongitude()); } onChanged(); return this; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + LATITUDE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( java.lang.Double.doubleToLongBits(getLatitude())); hash = (37 * hash) + LONGITUDE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( java.lang.Double.doubleToLongBits(getLongitude())); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Override protected LatLng getValue(com.google.datastore.v1.Value from) { return new LatLng( from.getGeoPointValue().getLatitude(), from.getGeoPointValue().getLongitude()); }
case GEO_POINT_VALUE: return new GeoPoint( v.getGeoPointValue().getLatitude(), v.getGeoPointValue().getLongitude()); case ARRAY_VALUE: List<Object> list = new ArrayList<>();