简体   繁体   中英

Custom input and output of altitude of the GeoPoint in OSMdroid

Can't read, evaluate the custom altitude for a given Geopoint in a List.

Basically I would like to have a path with x,y,Z, in Osmdroid. Z has to be ascending till middle of the path, then descending.(Z-value) Hold on, it has to be a Point or GeoPoint.

When I create a List it successfully adds a geopoint with altitude.

When I read it timer.setText("Your Coordinates are:" + marker.getPosition()+alt_S); in this setup(animation, interpolation) altitude remains 0.0.

Please help.

Thanks

The code below, reads latitude and Longitude of a marker, but it doesn't read the altitude that I try to obtain, when I stop animation.

Following this post: Osmdroid map marker animation

public void animateMarker(final Marker marker, final GeoPoint toPosition) {

    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toPixels(marker.getPosition(), null);

    final IGeoPoint startGeoPoint = proj.fromPixels(startPoint.x, startPoint.y);

    final long duration = 5000;
    LinearInterpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            for (int i = 0; i < geoPoints.size(); i++) {

                ListIterator<GeoPoint> geoPTS = geoPoints.listIterator();
                while (geoPTS.hasNext()) {
                    GeoPoint test = geoPTS.next();
                    // do something with o


                    double lng = t * toPosition.getLongitude() + (1 - t) * startGeoPoint.getLongitude();
                    double lat = t * toPosition.getLatitude() + (1 - t) * startGeoPoint.getLatitude();
                    double alt = test.getAltitude();

                    marker.setPosition(new GeoPoint(lat, lng,alt));



                    stopper = findViewById(R.id.buttonStop);


                    if (stopper.isPressed()) {
                        handler.removeCallbacks(this);
                        timer.getText();
                        alt_S = Double.toString(alt);
                        timer.setText("Your Coordinates are :" + marker.getPosition()+alt_S);
                    }




                }


            }
            if (t < 1.0) {
                handler.postDelayed(this, 15);
            }
            map.postInvalidate();


        }
    });
}

Folks, I ended up using fractions from 0.0001, than if my flying object exceeds or equal half of total 1, than subtract from altitude reached at the middle. Had to define duration of interpolation.(that's another story).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM