com.mapbox.mapboxsdk.geometry.LatLng Java Examples

The following examples show how to use com.mapbox.mapboxsdk.geometry.LatLng. 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: LineManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIgnoreClearedAnnotations() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  List<LatLng>latLngs = new ArrayList<>();
  latLngs.add(new LatLng());
  latLngs.add(new LatLng(1,1));
  LineOptions options = new LineOptions().withLatLngs(latLngs);
   Line  line = lineManager.create(options);
  assertEquals(1, lineManager.annotations.size());

  lineManager.getAnnotations().clear();
  lineManager.updateSource();
  assertTrue(lineManager.getAnnotations().isEmpty());

  lineManager.update(line);
  assertTrue(lineManager.getAnnotations().isEmpty());
}
 
Example #2
Source File: MyLocationMapActivity.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
private void zoomTo(Location location, boolean force) {
    // only zoom to user's location once
    if (!hasLoadedMyLocation || force) {

        // move map camera
        int duration = getMapView().getMap().getCameraPosition().zoom < 10 ? 2500 : 1000;
        getMapView().getMap().animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13), duration);

        // stop location requests
        locationComponent.getLocationEngine().removeLocationUpdates(new LocationEngineCallback<LocationEngineResult>() {
            @Override
            public void onSuccess(LocationEngineResult result) {}

            @Override
            public void onFailure(@NonNull Exception exception) {}
        });
        hasLoadedMyLocation = true;

        // save location to prefs
        PreferenceManager.getDefaultSharedPreferences(this)
                .edit()
                .putFloat(AirMapConstants.LAST_LOCATION_LATITUDE, (float) location.getLatitude())
                .putFloat(AirMapConstants.LAST_LOCATION_LONGITUDE, (float) location.getLongitude())
                .apply();
    }
}
 
Example #3
Source File: PrkngDataDownloadTask.java    From android with MIT License 6 votes vote down vote up
protected void drawRadius(LatLng center, LatLng northWest) {
    final LatLng realNW = vMap.fromScreenLocation(new PointF(0, 0));
    final LatLng realCenter = vMap.getLatLng();

    vMap.addMarker(new MarkerOptions().position(northWest));
    vMap.addMarker(new MarkerOptions().position(center));
    vMap.addMarker(new MarkerOptions().position(realNW));
    vMap.addMarker(new MarkerOptions().position(realCenter));

    vMap.addPolyline(new PolylineOptions()
            .add(new LatLng[]{center, northWest})
            .color(Color.GREEN)
            .width(5));

    vMap.addPolyline(new PolylineOptions()
            .add(new LatLng[]{realCenter, realNW})
            .color(Color.YELLOW)
            .width(5));
}
 
Example #4
Source File: PointMath.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the intersection between 2 lines, if it exists
 * @param line1 Line 1 to check
 * @param line2 Line 2 to check
 * @return null if no intersection, otherwise the intersection point
 */
@Nullable
private static LatLng lineIntersect(Line line1, Line line2) {
    double x1 = line1.a.getLatitude();
    double y1 = line1.a.getLongitude();
    double x2 = line1.b.getLatitude();
    double y2 = line1.b.getLongitude();
    double x3 = line2.a.getLatitude();
    double y3 = line2.a.getLongitude();
    double x4 = line2.b.getLatitude();
    double y4 = line2.b.getLongitude();
    double denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
    if (denom == 0.0) { // Lines are parallel.
        return null;
    }
    double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
    double ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
    if (ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f) {
        // Get the intersection point.
        return new LatLng((x1 + ua * (x2 - x1)), (y1 + ua * (y2 - y1)));
    }
    return null;
}
 
Example #5
Source File: LineManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void addLines() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  List<List<LatLng>> latLngList = new ArrayList<>();
  latLngList.add(new ArrayList<LatLng>() {{
    add(new LatLng(2, 2));
    add(new LatLng(2, 3));
  }});
  latLngList.add(new ArrayList<LatLng>() {{
    add(new LatLng(1, 1));
    add(new LatLng(2, 3));
  }});
  List<LineOptions> options = new ArrayList<>();
  for (List<LatLng> latLngs : latLngList) {
    options.add(new LineOptions().withLatLngs(latLngs));
  }
  List<Line> lines = lineManager.create(options);
  assertTrue("Returned value size should match", lines.size() == 2);
  assertTrue("Annotations size should match", lineManager.getAnnotations().size() == 2);
}
 
Example #6
Source File: PolygonContainer.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public LatLng[] getNeighborPoints(LatLng point) {
    LatLng closestPoint = getClosestPointOrMidpoint(point);
    int index = path.indexOf(closestPoint);

    // midpoint
    if (index == -1) {
        index = midpoints.indexOf(closestPoint);
        if (index == 0) {
            return new LatLng[]{path.get(0), path.get(1)};
        } else {
            return new LatLng[]{path.get(index), path.get(index + 1)};
        }

    // point
    } else {
        if (index == 0) {
            return new LatLng[]{path.get(path.size() - 2), path.get(index + 1)};
        } else if (index == path.size() - 2) {
            return new LatLng[]{path.get(index - 1), path.get(index + 1)};
        } else {
            return new LatLng[]{path.get(index - 1), path.get(index + 1)};
        }
    }
}
 
Example #7
Source File: MapUtils.java    From android with MIT License 6 votes vote down vote up
public static void setInitialCenterCoordinates(final MapView mapView, Bundle extras) throws UnsupportedAreaException {
    final long startMillis = System.currentTimeMillis();

    final LatLngZoom initialCoords = MapUtils
            .getInitialCenterCoordinates(mapView, extras);

    if (initialCoords != null) {
        mapView.setLatLng((LatLng) initialCoords);
        mapView.setZoom(initialCoords.getZoom(), true);
    } else if (mapView.isMyLocationEnabled()) {
        mapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(Location location) {
                if (System.currentTimeMillis() - startMillis > DateUtils.SECOND_IN_MILLIS) {
                    mapView.setOnMyLocationChangeListener(null);
                } else if (CityBoundsHelper.isValidLocation(mapView.getContext(), location)) {
                    mapView.setOnMyLocationChangeListener(null);

                    mapView.setLatLng(new LatLng(
                            location.getLatitude(), location.getLongitude()));
                    mapView.setZoom(Const.UiConfig.MY_LOCATION_ZOOM, true);
                }
            }
        });
    }
}
 
Example #8
Source File: PolygonContainer.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public boolean checkForIntersections() {
    List<LatLng> points = PointMath.findIntersections(path);
    if (points.isEmpty()) {
        return false;
    }

    List<Point> intersections = latLngsToPositions(points);
    if (map.getStyle().getLayer(INTERSECTION_LAYER) == null) {
        Source intersectionSource = new GeoJsonSource(INTERSECTION_SOURCE, Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
        map.getStyle().addSource(intersectionSource);
        Layer intersectionLayer = new SymbolLayer(INTERSECTION_LAYER, INTERSECTION_SOURCE)
                .withProperties(PropertyFactory.iconImage(INTERSECTION_IMAGE));
        map.getStyle().addLayer(intersectionLayer);
    } else {
        GeoJsonSource intersectionsSource = map.getStyle().getSourceAs(INTERSECTION_SOURCE);
        intersectionsSource.setGeoJson(Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
    }

    return true;
}
 
Example #9
Source File: RegionSelectionFragment.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
OfflineRegionDefinition createRegion() {
  if (mapboxMap == null) {
    throw new NullPointerException("MapboxMap is null and can't be used to create Offline region"
      + "definition.");
  }
  RectF rectF = getSelectionRegion();
  LatLng northEast = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.right, rectF.top));
  LatLng southWest = mapboxMap.getProjection().fromScreenLocation(new PointF(rectF.left, rectF.bottom));

  LatLngBounds bounds = new LatLngBounds.Builder().include(northEast).include(southWest).build();
  double cameraZoom = mapboxMap.getCameraPosition().zoom;
  float pixelRatio = getActivity().getResources().getDisplayMetrics().density;

  return new OfflineTilePyramidRegionDefinition(
    mapboxMap.getStyle().getUrl(), bounds, cameraZoom - 2, cameraZoom + 2, pixelRatio
  );
}
 
Example #10
Source File: PolygonContainer.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
private LatLng getClosestPointOrMidpoint(LatLng latLng) {
    double shortestDistance = Double.MAX_VALUE;
    LatLng closestPoint = null;

    List<LatLng> allPoints = new ArrayList<>(path);
    allPoints.addAll(midpoints);
    for (LatLng pathPoint : allPoints) {
        double dist = latLng.distanceTo(pathPoint);
        if (closestPoint == null || dist < shortestDistance) {
            closestPoint = pathPoint;
            shortestDistance = dist;
        }
    }

    return closestPoint;
}
 
Example #11
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 #12
Source File: NavigationCamera.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
/**
 * Creates an initial animation with the given {@link RouteInformation#route()}.
 * <p>
 * This is the first animation that fires prior to receiving progress updates.
 * <p>
 * If a user interacts with the {@link MapboxMap} while the animation is in progress,
 * the animation will be cancelled.  So it's important to add the {@link ProgressChangeListener}
 * in both onCancel() and onFinish() scenarios.
 *
 * @param routeInformation with route data
 */
private void animateCameraFromRoute(RouteInformation routeInformation) {

  Camera cameraEngine = navigation.getCameraEngine();

  Point targetPoint = cameraEngine.target(routeInformation);
  LatLng targetLatLng = new LatLng(targetPoint.latitude(), targetPoint.longitude());
  double bearing = cameraEngine.bearing(routeInformation);
  double zoom = cameraEngine.zoom(routeInformation);

  CameraPosition position = new CameraPosition.Builder()
    .target(targetLatLng)
    .bearing(bearing)
    .zoom(zoom)
    .build();

  updateMapCameraPosition(position, new AddProgressListenerCancelableCallback(navigation, progressChangeListener));
}
 
Example #13
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 #14
Source File: CircleContainer.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public void move(LatLng center) {
    this.center = center;
    this.points = calculateCirclePoints(center, radius);

    List<Point> positions = latLngsToPositions(points);
    List<List<Point>> coordinates = new ArrayList<>();
    coordinates.add(positions);

    List<Point> lineString = new ArrayList<>(positions);
    lineString.add(positions.get(0));

    GeoJsonSource pointSource = map.getStyle().getSourceAs(POINT_SOURCE);
    pointSource.setGeoJson(Feature.fromGeometry(Point.fromLngLat(center.getLongitude(), center.getLatitude())));

    GeoJsonSource polygonSource = map.getStyle().getSourceAs(POLYGON_SOURCE);
    polygonSource.setGeoJson(Feature.fromGeometry(Polygon.fromLngLats(coordinates)));

    FillLayer polygonFill = map.getStyle().getLayerAs(Container.POLYGON_LAYER);
    polygonFill.setProperties(PropertyFactory.fillColor(ContextCompat.getColor(context, R.color.colorAccent)));

    GeoJsonSource polylineSource = map.getStyle().getSourceAs(POLYLINE_SOURCE);
    polylineSource.setGeoJson(Feature.fromGeometry(LineString.fromLngLats(lineString)));
}
 
Example #15
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void setEventInfo(Pair<ProgramEventViewModel, LatLng> eventInfo) {
    if (currentMarker != null) {
        markerViewManager.removeMarker(currentMarker);
    }
    InfoWindowEventBinding binding = InfoWindowEventBinding.inflate(LayoutInflater.from(this));
    binding.setEvent(eventInfo.val0());
    binding.setPresenter(presenter);
    View view = binding.getRoot();
    view.setOnClickListener(viewClicked ->
            markerViewManager.removeMarker(currentMarker));
    view.setOnLongClickListener(view1 -> {
        presenter.onEventClick(eventInfo.val0().uid(), eventInfo.val0().orgUnitUid());
        return true;
    });
    view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    currentMarker = new MarkerView(eventInfo.val1(), view);
    markerViewManager.addMarker(currentMarker);
}
 
Example #16
Source File: MapView.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Zoom the map to enclose the specified bounding box, as closely as
 * possible.
 *
 * @param boundingBox the box to compute the zoom for
 * @param regionFit   if true computed zoom will make sure the whole box is visible
 * @param animated    if true the zoom will be animated
 * @param roundedZoom if true the required zoom will be rounded (for better
 *                    graphics)
 * @param userAction  set to true if it comes from a userAction
 * @return the map view, for chaining
 */
public MapView zoomToBoundingBox(final BoundingBox boundingBox,
                                 final boolean regionFit, final boolean animated,
                                 final boolean roundedZoom, final boolean userAction) {
    BoundingBox inter = (mScrollableAreaBoundingBox != null) ? mScrollableAreaBoundingBox
            .intersect(boundingBox) : boundingBox;
    if (inter == null || !inter.isValid()) {
        return this;
    }
    if (!mLayedOut) {
        mBoundingBoxToZoomOn = inter;
        mBoundingBoxToZoomOnRegionFit = regionFit;
        return this;
    }

    // Zoom to boundingBox center, at calculated maximum allowed zoom level
    final LatLng center = inter.getCenter();
    final float zoom = (float) minimumZoomForBoundingBox(inter, regionFit,
            roundedZoom);

    if (animated) {
        getController().setZoomAnimated(zoom, center, true, userAction);
    } else {
        getController().setZoom(zoom, center, userAction);
    }
    return this;
}
 
Example #17
Source File: MapUtils.java    From android with MIT License 5 votes vote down vote up
public static double distanceTo(@NonNull LatLng point, @NonNull Annotation annotation) {
    if (annotation instanceof Marker) {
        return point.distanceTo(((Marker) annotation).getPosition());
    } else if (annotation instanceof Polyline) {
        double minDistance = Double.MAX_VALUE;
        for (LatLng latLng : ((Polyline) annotation).getPoints()) {
            minDistance = Math.min(minDistance, latLng.distanceTo(point));
        }
        return minDistance;
    }

    return Double.MAX_VALUE;
}
 
Example #18
Source File: CircleManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testIgnoreClearedAnnotations() {
  circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  CircleOptions options = new CircleOptions().withLatLng(new LatLng());
   Circle  circle = circleManager.create(options);
  assertEquals(1, circleManager.annotations.size());

  circleManager.getAnnotations().clear();
  circleManager.updateSource();
  assertTrue(circleManager.getAnnotations().isEmpty());

  circleManager.update(circle);
  assertTrue(circleManager.getAnnotations().isEmpty());
}
 
Example #19
Source File: SymbolManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testIconAnchorLayerProperty() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(symbolLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(iconAnchor(get("icon-anchor")))));

  SymbolOptions options = new SymbolOptions().withLatLng(new LatLng()).withIconAnchor(ICON_ANCHOR_CENTER);
  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(iconAnchor(get("icon-anchor")))));

  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(iconAnchor(get("icon-anchor")))));
}
 
Example #20
Source File: SymbolManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testTextOffsetLayerProperty() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(symbolLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(textOffset(get("text-offset")))));

  SymbolOptions options = new SymbolOptions().withLatLng(new LatLng()).withTextOffset(new Float[] {0f, 0f});
  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(textOffset(get("text-offset")))));

  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(textOffset(get("text-offset")))));
}
 
Example #21
Source File: NotifyUtils.java    From android with MIT License 5 votes vote down vote up
private static PendingIntent getClickIntent(Context context, LatLng latLng) {
    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
    return PendingIntent.getActivity(
            context,
            0,
            MainActivity.newIntent(context, latLng),
            PendingIntent.FLAG_UPDATE_CURRENT
    );
}
 
Example #22
Source File: NavigationLauncherActivity.java    From graphhopper-navigation-example with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"MissingPermission"})
private void initLocationLayer() {
    locationLayer = new LocationLayerPlugin(mapView, mapboxMap);
    locationLayer.setRenderMode(RenderMode.COMPASS);
    Location lastKnownLocation = getLastKnownLocation();
    if (lastKnownLocation != null) {
        // TODO we could think about zoom to the user location later on as well
        animateCamera(new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude()));
    }
}
 
Example #23
Source File: LineManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testLineOffsetLayerProperty() {
  lineManager = new LineManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(lineLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(lineOffset(get("line-offset")))));

  List<LatLng>latLngs = new ArrayList<>();
  latLngs.add(new LatLng());
  latLngs.add(new LatLng(1,1));
  LineOptions options = new LineOptions().withLatLngs(latLngs).withLineOffset(0.3f);
  lineManager.create(options);
  verify(lineLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(lineOffset(get("line-offset")))));

  lineManager.create(options);
  verify(lineLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(lineOffset(get("line-offset")))));
}
 
Example #24
Source File: MainMapFragment.java    From android with MIT License 5 votes vote down vote up
@Override
public void setCenterCoordinate(LatLng center) {
    setCenterCoordinate(new LatLngZoom(
            center.getLatitude(),
            center.getLongitude(),
            vMap.getZoom()
    ));
}
 
Example #25
Source File: MapView.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get centerpoint of the phone as latitude and longitude.
 *
 * @return centerpoint
 */
public LatLng getCenter() {
    final int worldSize_current_2 = Projection.mapSize(mZoomLevel) >> 1;
    return Projection.pixelXYToLatLong((float) mDScroll.x
                    + worldSize_current_2, (float) mDScroll.y + worldSize_current_2,
            mZoomLevel
    );
}
 
Example #26
Source File: SymbolManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testTextLetterSpacingLayerProperty() {
  symbolManager = new SymbolManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(symbolLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(textLetterSpacing(get("text-letter-spacing")))));

  SymbolOptions options = new SymbolOptions().withLatLng(new LatLng()).withTextLetterSpacing(0.3f);
  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(textLetterSpacing(get("text-letter-spacing")))));

  symbolManager.create(options);
  verify(symbolLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(textLetterSpacing(get("text-letter-spacing")))));
}
 
Example #27
Source File: PointMath.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates midpoints of the line segments that make up a given shape
 * @param shape A polygon
 * @return a list of midpoints of the given shape
 */
public static List<LatLng> getMidpointsFromLatLngs(List<LatLng> shape) {
    List<LatLng> midpoints = new ArrayList<>();
    for (int i = 1; i < shape.size(); i++) {
        double lat = (shape.get(i - 1).getLatitude() + shape.get(i).getLatitude()) / 2;
        double lng = (shape.get(i - 1).getLongitude() + shape.get(i).getLongitude()) / 2;
        midpoints.add(new LatLng(lat, lng));
    }
    return midpoints;
}
 
Example #28
Source File: GeocoderAdapter.java    From android with MIT License 5 votes vote down vote up
public GeocoderAdapter(Context context, LatLng proximity) {
    this.context = context;
    this.features = new ArrayList<>();
    this.geocoderFilter = new GeocoderFilter(proximity,
            CityBoundsHelper.getNearestCity(context, proximity));

    this.mapboxToken = context.getString(R.string.mapbox_access_token);
    this.foursquareClientId = context.getString(R.string.foursquare_client_id);
    this.foursquareClientSecret = context.getString(R.string.foursquare_client_secret);
    this.foursquareVersion = context.getString(R.string.foursquare_version);
}
 
Example #29
Source File: FillManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testFeatureIdFill() {
  fillManager = new FillManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  List<LatLng>innerLatLngs = new ArrayList<>();
  innerLatLngs.add(new LatLng());
  innerLatLngs.add(new LatLng(1,1));
  innerLatLngs.add(new LatLng(-1,-1));
  List<List<LatLng>>latLngs = new ArrayList<>();
  latLngs.add(innerLatLngs);
  Fill fillZero = fillManager.create(new FillOptions().withLatLngs(latLngs));
  Fill fillOne = fillManager.create(new FillOptions().withLatLngs(latLngs));
  assertEquals(fillZero.getFeature().get(Fill.ID_KEY).getAsLong(), 0);
  assertEquals(fillOne.getFeature().get(Fill.ID_KEY).getAsLong(), 1);
}
 
Example #30
Source File: CircleManagerTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testCircleStrokeColorLayerProperty() {
  circleManager = new CircleManager(mapView, mapboxMap, style, coreElementProvider, null, null, draggableAnnotationController);
  verify(circleLayer, times(0)).setProperties(argThat(new PropertyValueMatcher(circleStrokeColor(get("circle-stroke-color")))));

  CircleOptions options = new CircleOptions().withLatLng(new LatLng()).withCircleStrokeColor("rgba(0, 0, 0, 1)");
  circleManager.create(options);
  verify(circleLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(circleStrokeColor(get("circle-stroke-color")))));

  circleManager.create(options);
  verify(circleLayer, times(1)).setProperties(argThat(new PropertyValueMatcher(circleStrokeColor(get("circle-stroke-color")))));
}