Java Code Examples for org.osmdroid.views.overlay.Marker#getPosition()

The following examples show how to use org.osmdroid.views.overlay.Marker#getPosition() . 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: MarkerAnimation.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static ValueAnimator animateMarkerToHC(final MapView map, final Marker marker, final GeoPoint finalPosition, final GeoPointInterpolator GeoPointInterpolator) {
    final GeoPoint startPosition = marker.getPosition();

    ValueAnimator valueAnimator = new ValueAnimator();
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float v = animation.getAnimatedFraction();
            GeoPoint newPosition = GeoPointInterpolator.interpolate(v, startPosition, finalPosition);
            marker.setPosition(newPosition);
            map.invalidate();

        }
    });
    valueAnimator.setFloatValues(0, 1); // Ignored.
    valueAnimator.setDuration(3000);
    valueAnimator.start();
    return valueAnimator;
}
 
Example 2
Source File: MarkerAnimation.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static void animateMarkerToGB(final MapView map, final Marker marker, final GeoPoint finalPosition, final GeoPointInterpolator GeoPointInterpolator) {
    final GeoPoint startPosition = marker.getPosition();
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final Interpolator interpolator = new AccelerateDecelerateInterpolator();
    final float durationInMs = 3000;

    handler.post(new Runnable() {
        long elapsed;
        float t;
        float v;

        @Override
        public void run() {
            // Calculate progress using interpolator
            elapsed = SystemClock.uptimeMillis() - start;
            t = elapsed / durationInMs;
            v = interpolator.getInterpolation(t);

            marker.setPosition(GeoPointInterpolator.interpolate(v, startPosition, finalPosition));
            map.invalidate();
            // Repeat till progress is complete.
            if (t < 1) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });
}
 
Example 3
Source File: OsmdroidShapeMarkers.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Polygon add a marker in the list of markers to where it is closest to the
 * the surrounding points
 *
 * @param marker
 * @param markers
 */
public static void addMarkerAsPolygon(Marker marker, List<Marker> markers) {
    IGeoPoint position = marker.getPosition();
    int insertLocation = markers.size();
    if (markers.size() > 2) {
        double[] distances = new double[markers.size()];
        insertLocation = 0;
        distances[0] = SphericalUtil.computeDistanceBetween(position,
                markers.get(0).getPosition());
        for (int i = 1; i < markers.size(); i++) {
            distances[i] = SphericalUtil.computeDistanceBetween(position,
                    markers.get(i).getPosition());
            if (distances[i] < distances[insertLocation]) {
                insertLocation = i;
            }
        }

        int beforeLocation = insertLocation > 0 ? insertLocation - 1
                : distances.length - 1;
        int afterLocation = insertLocation < distances.length - 1 ? insertLocation + 1
                : 0;

        if (distances[beforeLocation] > distances[afterLocation]) {
            insertLocation = afterLocation;
        }

    }
    markers.add(insertLocation, marker);
}
 
Example 4
Source File: OsmdroidShapeMarkers.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
/**
 * Polyline add a marker in the list of markers to where it is closest to
 * the the surrounding points
 *
 * @param marker
 * @param markers
 */
public static void addMarkerAsPolyline(Marker marker, List<Marker> markers) {
    GeoPoint position = marker.getPosition();
    int insertLocation = markers.size();
    if (markers.size() > 1) {
        double[] distances = new double[markers.size()];
        insertLocation = 0;
        distances[0] = SphericalUtil.computeDistanceBetween(position,
                markers.get(0).getPosition());
        for (int i = 1; i < markers.size(); i++) {
            distances[i] = SphericalUtil.computeDistanceBetween(position,
                    markers.get(i).getPosition());
            if (distances[i] < distances[insertLocation]) {
                insertLocation = i;
            }
        }

        Integer beforeLocation = insertLocation > 0 ? insertLocation - 1
                : null;
        Integer afterLocation = insertLocation < distances.length - 1 ? insertLocation + 1
                : null;

        if (beforeLocation != null && afterLocation != null) {
            if (distances[beforeLocation] > distances[afterLocation]) {
                insertLocation = afterLocation;
            }
        } else if (beforeLocation != null) {
            if (distances[beforeLocation] >= SphericalUtil
                    .computeDistanceBetween(markers.get(beforeLocation)
                            .getPosition(), markers.get(insertLocation)
                            .getPosition())) {
                insertLocation++;
            }
        } else {
            if (distances[afterLocation] < SphericalUtil
                    .computeDistanceBetween(markers.get(afterLocation)
                            .getPosition(), markers.get(insertLocation)
                            .getPosition())) {
                insertLocation++;
            }
        }

    }
    markers.add(insertLocation, marker);
}