Java Code Examples for com.mapbox.mapboxsdk.geometry.LatLng#getLatitude()

The following examples show how to use com.mapbox.mapboxsdk.geometry.LatLng#getLatitude() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-example with Apache License 2.0 6 votes vote down vote up
@Override
public void onDialogPositiveClick(DialogFragment dialog) {
    EditText jobId = dialog.getDialog().findViewById(R.id.job_id);
    // Check if it's a solution fetch
    if (jobId != null) {
        EditText vehicleId = dialog.getDialog().findViewById(R.id.vehicle_id);

        fetchVrpSolution(jobId.getText().toString(), vehicleId.getText().toString());
    }
    // Check if it's a geocoding search
    EditText search = dialog.getDialog().findViewById(R.id.geocoding_input_id);
    if (search != null) {
        currentGeocodingInput = search.getText().toString();

        showLoading();
        String point = null;
        LatLng pointLatLng = this.mapboxMap.getCameraPosition().target;
        if (pointLatLng != null)
            point = pointLatLng.getLatitude() + "," + pointLatLng.getLongitude();
        new FetchGeocodingTask(this, getString(R.string.gh_key)).execute(new FetchGeocodingConfig(currentGeocodingInput, getLanguageFromSharedPreferences().getLanguage(), 5, false, point, "default"));
    }

}
 
Example 2
Source File: Circle.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
@Nullable
Geometry getOffsetGeometry(@NonNull Projection projection, @NonNull MoveDistancesObject moveDistancesObject,
                           float touchAreaShiftX, float touchAreaShiftY) {
  PointF pointF = new PointF(
    moveDistancesObject.getCurrentX() - touchAreaShiftX,
    moveDistancesObject.getCurrentY() - touchAreaShiftY
  );

  LatLng latLng = projection.fromScreenLocation(pointF);
  if (latLng.getLatitude() > MAX_MERCATOR_LATITUDE || latLng.getLatitude() < MIN_MERCATOR_LATITUDE) {
    return null;
  }

  return Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
}
 
Example 3
Source File: Line.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
@Nullable
Geometry getOffsetGeometry(@NonNull Projection projection, @NonNull MoveDistancesObject moveDistancesObject,
                           float touchAreaShiftX, float touchAreaShiftY) {
  List<Point> originalPoints = geometry.coordinates();
  List<Point> resultingPoints = new ArrayList<>(originalPoints.size());
  for (Point jsonPoint : originalPoints) {
    PointF pointF = projection.toScreenLocation(new LatLng(jsonPoint.latitude(), jsonPoint.longitude()));
    pointF.x -= moveDistancesObject.getDistanceXSinceLast();
    pointF.y -= moveDistancesObject.getDistanceYSinceLast();

    LatLng latLng = projection.fromScreenLocation(pointF);
    if (latLng.getLatitude() > MAX_MERCATOR_LATITUDE || latLng.getLatitude() < MIN_MERCATOR_LATITUDE) {
      return null;
    }
    resultingPoints.add(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
  }

  return LineString.fromLngLats(resultingPoints);
}
 
Example 4
Source File: Symbol.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
@Nullable
Geometry getOffsetGeometry(@NonNull Projection projection, @NonNull MoveDistancesObject moveDistancesObject,
                           float touchAreaShiftX, float touchAreaShiftY) {
  PointF pointF = new PointF(
    moveDistancesObject.getCurrentX() - touchAreaShiftX,
    moveDistancesObject.getCurrentY() - touchAreaShiftY
  );

  LatLng latLng = projection.fromScreenLocation(pointF);
  if (latLng.getLatitude() > MAX_MERCATOR_LATITUDE || latLng.getLatitude() < MIN_MERCATOR_LATITUDE) {
    return null;
  }

  return Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
}
 
Example 5
Source File: CircleContainer.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public static ArrayList<LatLng> calculateCirclePoints(LatLng location, double radius) {
    int degreesBetweenPoints = 8;
    int numberOfPoints = (int) Math.floor(360 / degreesBetweenPoints);
    double distRadians = radius / 6371000.0; // earth radius in meters
    double centerLatRadians = location.getLatitude() * Math.PI / 180;
    double centerLonRadians = location.getLongitude() * Math.PI / 180;
    ArrayList<LatLng> polygons = new ArrayList<>(); //array to hold all the path
    for (int index = 0; index < numberOfPoints; index++) {
        double degrees = index * degreesBetweenPoints;
        double degreeRadians = degrees * Math.PI / 180;
        double pointLatRadians = Math.asin(Math.sin(centerLatRadians) * Math.cos(distRadians) + Math.cos(centerLatRadians) * Math.sin(distRadians) * Math.cos(degreeRadians));
        double pointLonRadians = centerLonRadians + Math.atan2(Math.sin(degreeRadians) * Math.sin(distRadians) * Math.cos(centerLatRadians),
                Math.cos(distRadians) - Math.sin(centerLatRadians) * Math.sin(pointLatRadians));
        double pointLat = pointLatRadians * 180 / Math.PI;
        double pointLon = pointLonRadians * 180 / Math.PI;
        polygons.add(new LatLng(pointLat, pointLon));
    }
    return polygons;
}
 
Example 6
Source File: AnnotationsFactory.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public ArrayList<LatLng> polygonCircleForCoordinate(LatLng location, double radius) {
    int degreesBetweenPoints = 8;
    int numberOfPoints = (int) Math.floor(360 / degreesBetweenPoints);
    double distRadians = radius / 6371000.0; // earth radius in meters
    double centerLatRadians = location.getLatitude() * Math.PI / 180;
    double centerLonRadians = location.getLongitude() * Math.PI / 180;
    ArrayList<LatLng> polygons = new ArrayList<>(); //array to hold all the points
    for (int index = 0; index < numberOfPoints; index++) {
        double degrees = index * degreesBetweenPoints;
        double degreeRadians = degrees * Math.PI / 180;
        double pointLatRadians = Math.asin(Math.sin(centerLatRadians) * Math.cos(distRadians) + Math.cos(centerLatRadians) * Math.sin(distRadians) * Math.cos(degreeRadians));
        double pointLonRadians = centerLonRadians + Math.atan2(Math.sin(degreeRadians) * Math.sin(distRadians) * Math.cos(centerLatRadians),
                Math.cos(distRadians) - Math.sin(centerLatRadians) * Math.sin(pointLatRadians));
        double pointLat = pointLatRadians * 180 / Math.PI;
        double pointLon = pointLonRadians * 180 / Math.PI;
        LatLng point = new LatLng(pointLat, pointLon);
        polygons.add(point);
    }
    return polygons;
}
 
Example 7
Source File: MapTileLayerArray.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public LatLng getCenterCoordinate() {
    float latitude = 0;
    float longitude = 0;
    int nb = 0;
    synchronized (mTileProviderList) {
        for (final MapTileModuleLayerBase tileProvider : mTileProviderList) {
            LatLng providerCenter = tileProvider.getCenterCoordinate();
            if (providerCenter != null) {
                latitude += providerCenter.getLatitude();
                longitude += providerCenter.getLongitude();
                nb++;
            }
        }
    }
    if (nb > 0) {
        latitude /= nb;
        longitude /= nb;
        return new LatLng(latitude, longitude);
    }
    return null;
}
 
Example 8
Source File: Fill.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
@Nullable
Geometry getOffsetGeometry(@NonNull Projection projection, @NonNull MoveDistancesObject moveDistancesObject,
                           float touchAreaShiftX, float touchAreaShiftY) {
  List<List<Point>> originalPoints = geometry.coordinates();
  if (originalPoints != null) {
    List<List<Point>> resultingPoints = new ArrayList<>(originalPoints.size());
    for (List<Point> points : originalPoints) {
      List<Point> innerPoints = new ArrayList<>();
      for (Point jsonPoint : points) {
        PointF pointF = projection.toScreenLocation(new LatLng(jsonPoint.latitude(), jsonPoint.longitude()));
        pointF.x -= moveDistancesObject.getDistanceXSinceLast();
        pointF.y -= moveDistancesObject.getDistanceYSinceLast();

        LatLng latLng = projection.fromScreenLocation(pointF);
        if (latLng.getLatitude() > MAX_MERCATOR_LATITUDE || latLng.getLatitude() < MIN_MERCATOR_LATITUDE) {
          return null;
        }
        innerPoints.add(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
      }
      resultingPoints.add(innerPoints);
    }

    return Polygon.fromLngLats(resultingPoints);
  }

  return null;
}
 
Example 9
Source File: CheckinData.java    From android with MIT License 5 votes vote down vote up
public CheckinData(long id, long checkinAt, long checkoutAt, String address, LatLng latLng) {
    this.id = id;
    this.checkinAt = new Date(checkinAt);
    this.checkoutAt = !Long.valueOf(Const.UNKNOWN_VALUE).equals(checkoutAt) ?
            new Date(checkoutAt) : null;
    this.address = address;
    this.latitude = latLng.getLatitude();
    this.longitude = latLng.getLongitude();
}
 
Example 10
Source File: IntentUtils.java    From android with MIT License 5 votes vote down vote up
public static Intent getDirectionsIntent(LatLng origin, LatLng destination) {
    if (destination == null) {
        return null;
    }

    final String sDestination = destination.getLatitude() + "," + destination.getLongitude();
    final String sOrigin = (origin != null ?
            origin.getLatitude() + "," + origin.getLongitude() : "");

    final Uri uri = Uri.parse(String.format(GOOGLE_MAPS,
            sOrigin,
            sDestination));
    return new Intent(Intent.ACTION_VIEW, uri);
}
 
Example 11
Source File: SphericalMercatorProjection.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public Point toPoint(final LatLng latLng) {
    final double x = latLng.getLatitude() / 360 + .5;
    final double siny = Math.sin(Math.toRadians(latLng.getLatitude()));
    final double y = 0.5 * Math.log((1 + siny) / (1 - siny)) / -(2 * Math.PI) + .5;

    return new Point(x * mWorldWidth, y * mWorldWidth);
}
 
Example 12
Source File: UserLocationOverlay.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean goToMyPosition(final boolean animated) {
    if (mLocation == null) {
        return false;
    }
    float currentZoom = mMapView.getZoomLevel(false);
    if (currentZoom <= mRequiredZoomLevel) {
        double requiredZoom = mRequiredZoomLevel;
        if (mZoomBasedOnAccuracy && mMapView.isLayedOut()) {
            double delta = (mLocation.getAccuracy() / 110000) * 1.2; // approx. meter per degree latitude, plus some margin
            final Projection projection = mMapView.getProjection();
            LatLng desiredSouthWest = new LatLng(mLocation.getLatitude() - delta,
                    mLocation.getLongitude() - delta);

            LatLng desiredNorthEast = new LatLng(mLocation.getLatitude() + delta,
                    mLocation.getLongitude() + delta);

            float pixelRadius = Math.min(mMapView.getMeasuredWidth(), mMapView.getMeasuredHeight()) / 2;

            BoundingBox currentBox = projection.getBoundingBox();
            if (desiredNorthEast.getLatitude() != currentBox.getLatNorth() ||
                    desiredNorthEast.getLongitude() != currentBox.getLonEast() ||
                    desiredSouthWest.getLatitude() != currentBox.getLatSouth() ||
                    desiredSouthWest.getLongitude() != currentBox.getLonWest()) {
                mMapView.zoomToBoundingBox(new BoundingBox(desiredNorthEast, desiredSouthWest), true, animated, true);
            }
        } else if (animated) {
            return mMapController.setZoomAnimated((float) requiredZoom, mLatLng, true, false);
        } else {
            mMapController.setZoom((float) requiredZoom, mLatLng, false);
        }
    } else if (animated) {
       return mMapController.animateTo(mLatLng);
    } else {
        return mMapController.goTo(mLatLng, new PointF(0, 0));
    }
    return true;
}
 
Example 13
Source File: GeoUtils.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Build a BoundingBox for a List of LatLng
 * @param coordinates List of coordinates
 * @param padding Option padding.  Recommended 0.01.  Send in null to have no padding applied
 * @return BoundingBox containing the given List of LatLng
 */
public static BoundingBox findBoundingBoxForGivenLocations(List<LatLng> coordinates, Double padding) {
    double west = 0.0;
    double east = 0.0;
    double north = 0.0;
    double south = 0.0;

    for (int lc = 0; lc < coordinates.size(); lc++) {
        LatLng loc = coordinates.get(lc);
        if (lc == 0) {
            north = loc.getLatitude();
            south = loc.getLatitude();
            west = loc.getLongitude();
            east = loc.getLongitude();
        } else {
            if (loc.getLatitude() > north) {
                north = loc.getLatitude();
            } else if (loc.getLatitude() < south) {
                south = loc.getLatitude();
            }
            if (loc.getLongitude() < west) {
                west = loc.getLongitude();
            } else if (loc.getLongitude() > east) {
                east = loc.getLongitude();
            }
        }
    }

    // OPTIONAL - Add some extra "padding" for better map display
    if (padding != null) {
        north = north + padding;
        south = south - padding;
        west = west - padding;
        east = east + padding;
    }

    return new BoundingBox(north, east, south, west);
}
 
Example 14
Source File: MapActivity.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void saveMapPosition() {
    LatLng c = mapView.getCenter();
    float lat = (float) c.getLatitude();
    float lng = (float) c.getLongitude();
    float z = mapView.getZoomLevel();

    SharedPreferences.Editor editor = getPreferences(Context.MODE_PRIVATE).edit();
    editor.putFloat(PREVIOUS_LAT, lat);
    editor.putFloat(PREVIOUS_LNG, lng);
    editor.putFloat(PREVIOUS_ZOOM, z);
    editor.apply();
}
 
Example 15
Source File: OSMNode.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * This constructor is used when we are creating an new OSMElement,
 * such as when a new Node is created. This constructor assumes
 * that we are creating a NEW element in the current survey.
 */
public OSMNode(LatLng latLng) {
    super(); // super sets the element to be modified
    lat = latLng.getLatitude();
    lng = latLng.getLongitude();
}
 
Example 16
Source File: OSMNode.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * This moves an OSMNode to a new location on the map.
 *
 * The LatLng in the node is reset, the LatLng in the
 * marker is reset, and the node is removed and replaced
 * in the JTSModel's spatial index.
 *
 * @param jtsModel - the model in which the node is spatially indexed
 * @param latLng - the new location to move the node to
 */
public void move(JTSModel jtsModel, LatLng latLng) {
    lat = latLng.getLatitude();
    lng = latLng.getLongitude();
    jtsModel.removeOSMElement(this);
    jtsModel.addOSMStandaloneNode(this);
    if (marker != null) {
        marker.setPoint(latLng);
    }
}