Java Code Examples for org.osmdroid.util.GeoPoint#setLatitude()

The following examples show how to use org.osmdroid.util.GeoPoint#setLatitude() . 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: ShapeConverter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private static GeoPoint fixOutOfRange(GeoPoint point){
    if (point.getLatitude()>90.00)
        point.setLatitude(90.00);
    else if (point.getLatitude()<-90.00)
        point.setLatitude(-90.00);

    if (abs(point.getLongitude())>180.00){
        double longitude = point.getLongitude();
        double diff = longitude > 0 ? -360 : 360;
        while (abs(longitude) > 180)
            longitude += diff;
        point.setLongitude(longitude);
    }

    return point;
}
 
Example 2
Source File: LinearRing.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * @since 6.0.2
 */
public GeoPoint getCenter(final GeoPoint pReuse) {
	final GeoPoint out = pReuse != null ? pReuse : new GeoPoint(0., 0);
	final BoundingBox boundingBox = getBoundingBox();
	out.setLatitude(boundingBox.getCenterLatitude());
	out.setLongitude(boundingBox.getCenterLongitude());
	return out;
}
 
Example 3
Source File: IconPlottingOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
    if (markerIcon != null) {
        GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null);
        /*
         * <b>Note</b></b: when plotting a point off the map, the conversion from
             * screen coordinates to map coordinates will return values that are invalid from a latitude,longitude
             * perspective. Sometimes this is a wanted behavior and sometimes it isn't. We are leaving it up to you,
             * the developer using osmdroid to decide on what is right for your application. See
             * <a href="https://github.com/osmdroid/osmdroid/pull/722">https://github.com/osmdroid/osmdroid/pull/722</a>
             * for more information and the discussion associated with this.
         */

        //just in case the point is off the map, let's fix the coordinates
        if (pt.getLongitude() < -180)
            pt.setLongitude(pt.getLongitude()+360);
        if (pt.getLongitude() > 180)
            pt.setLongitude(pt.getLongitude()-360);
        //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
        if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
            pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
        if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
            pt.setLatitude(mapView.getTileSystem().getMinLatitude());

        Marker m = new Marker(mapView);
        m.setPosition(pt);
        m.setIcon(markerIcon);
        m.setImage(markerIcon);
        m.setTitle("A demo title");
        m.setSubDescription("A demo sub description\n" + pt.getLatitude() + "," + pt.getLongitude());
        m.setSnippet("a snippet of information");
        mapView.getOverlayManager().add(m);
        mapView.invalidate();
        return true;
    }
    return false;
}
 
Example 4
Source File: CirclePlottingOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {

    if (Configuration.getInstance().isDebugMapView()) {
        Log.d(IMapView.LOGTAG,"CirclePlottingOverlay onLongPress");
    }
    GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null);
        /*
         * <b>Note</b></b: when plotting a point off the map, the conversion from
             * screen coordinates to map coordinates will return values that are invalid from a latitude,longitude
             * perspective. Sometimes this is a wanted behavior and sometimes it isn't. We are leaving it up to you,
             * the developer using osmdroid to decide on what is right for your application. See
             * <a href="https://github.com/osmdroid/osmdroid/pull/722">https://github.com/osmdroid/osmdroid/pull/722</a>
             * for more information and the discussion associated with this.
         */

    //just in case the point is off the map, let's fix the coordinates
    if (pt.getLongitude() < -180)
        pt.setLongitude(pt.getLongitude() + 360);
    if (pt.getLongitude() > 180)
        pt.setLongitude(pt.getLongitude() - 360);
    //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
    if (pt.getLatitude() > 85.05112877980659)
        pt.setLatitude(85.05112877980659);
    if (pt.getLatitude() < -85.05112877980659)
        pt.setLatitude(-85.05112877980659);

    List<GeoPoint> circle = Polygon.pointsAsCircle(pt, distanceKm);
    Polygon p = new Polygon(mapView);
    p.setPoints(circle);
    p.setTitle("A circle");
    mapView.getOverlayManager().add(p);
    mapView.invalidate();
    return true;

}
 
Example 5
Source File: MilStdPointPlottingOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onLongPress(final MotionEvent e, final MapView mapView) {
    if (def != null) {
        GeoPoint pt = (GeoPoint) mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY(), null);

        //just in case the point is off the map, let's fix the coordinates
        if (pt.getLongitude() < -180)
            pt.setLongitude(pt.getLongitude() + 360);
        if (pt.getLongitude() > 180)
            pt.setLongitude(pt.getLongitude() - 360);
        //latitude is a bit harder. see https://en.wikipedia.org/wiki/Mercator_projection
        if (pt.getLatitude() > mapView.getTileSystem().getMaxLatitude())
            pt.setLatitude(mapView.getTileSystem().getMaxLatitude());
        if (pt.getLatitude() < mapView.getTileSystem().getMinLatitude())
            pt.setLatitude(mapView.getTileSystem().getMinLatitude());

        String code = def.getSymbolCode().replace("*", "-");
        //TODO if (!def.isMultiPoint())
        {
            int size = 128;

            SparseArray<String> attr = new SparseArray<>();
            attr.put(MilStdAttributes.PixelSize, size + "");

            ImageInfo ii = MilStdIconRenderer.getInstance().RenderIcon(code, def.getModifiers(), attr);
            Marker m = new Marker(mapView);
            m.setPosition(pt);
            m.setTitle(code);
            m.setSnippet(def.getDescription() + "\n" + def.getHierarchy());
            m.setSubDescription(def.getPath() + "\n" + m.getPosition().getLatitude() + "," + m.getPosition().getLongitude());

            if (ii != null && ii.getImage() != null) {
                BitmapDrawable d = new BitmapDrawable(ii.getImage());
                m.setImage(d);
                m.setIcon(d);

                int centerX = ii.getCenterPoint().x;    //pixel center position
                //calculate what percentage of the center this value is
                float realCenterX = (float) centerX / (float) ii.getImage().getWidth();

                int centerY = ii.getCenterPoint().y;
                float realCenterY = (float) centerY / (float) ii.getImage().getHeight();
                m.setAnchor(realCenterX, realCenterY);


                mapView.getOverlayManager().add(m);
                mapView.invalidate();
            }
        }

        return true;
    }
    return false;
}