org.osmdroid.util.GeoPoint Java Examples

The following examples show how to use org.osmdroid.util.GeoPoint. 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: OsmdroidMapWrapper.java    From osmdroid with Apache License 2.0 7 votes vote down vote up
@Override
public void addMarker(final Marker aMarker) {
	if (mItemizedOverlay == null) {
		// XXX this is a bit cumbersome. Maybe we should just do a simple ItemizedIconOverlay with null listener
		mItemizedOverlay = new ItemizedOverlayWithFocus<OverlayItem>(new ArrayList<OverlayItem>(), new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
			@Override
			public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
				return false;
			}

			@Override
			public boolean onItemLongPress(final int index, final OverlayItem item) {
				return false;
			}
		},this.mMapView.getContext());
		mItemizedOverlay.setFocusItemsOnTap(true);
		mMapView.getOverlays().add(mItemizedOverlay);
	}
	final OverlayItem item = new OverlayItem(aMarker.title, aMarker.snippet, new GeoPoint(aMarker.latitude, aMarker.longitude));
	if (aMarker.bitmap != null) {
		item.setMarker(new BitmapDrawable(mMapView.getResources(), aMarker.bitmap));
	} else {
		if (aMarker.icon != 0) {
			item.setMarker(mMapView.getResources().getDrawable(aMarker.icon));
		}
	}
	if (aMarker.anchor == Marker.Anchor.CENTER) {
		item.setMarkerHotspot(OverlayItem.HotspotPlace.CENTER);
	}
	mItemizedOverlay.addItem(item);
}
 
Example #2
Source File: WeatherGroundOverlaySample.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void addOverlays() {
    super.addOverlays();

    mOverlay = new GroundOverlay();
    mOverlay.setTransparency(0.5f);
    mOverlay.setPosition(mNorthEast, mSouthWest);
    mMapView.getOverlayManager().add(mOverlay);

    cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);

    mMapView.post(new Runnable() {
        @Override
        public void run() {
            final List<GeoPoint> geoPoints = new ArrayList<>();
            geoPoints.add(mNorthEast);
            geoPoints.add(mSouthWest);
            mMapView.zoomToBoundingBox(BoundingBox.fromGeoPoints(geoPoints), false, 50);
        }
    });

    Toast.makeText(getActivity(), "Downloading the weather image...", Toast.LENGTH_SHORT).show();
    new Thread(this).start();
}
 
Example #3
Source File: AnimatedMarkerValueAnimator.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


    View root = inflater.inflate(R.layout.sample_cachemgr, container,false);
    mMapView = new MapView(getActivity());
    ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView);
    btnCache = root.findViewById(R.id.btnCache);
    btnCache.setOnClickListener(this);
    btnCache.setText("Start/Stop Animation");

    marker = new Marker(mMapView);
    marker.setTitle("An animated marker");
    marker.setPosition(new GeoPoint(0d,0d));
    mMapView.getOverlayManager().add(marker);



    return root;
}
 
Example #4
Source File: OsmMapShapeConverter.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a {@link LineString} to a {@link PolylineOptions}
 *
 * @param lineString
 * @return
 */
public Polyline toPolyline(LineString lineString) {

    Polyline line = new Polyline();
    if (polylineOptions!=null) {
        line.setTitle(polylineOptions.getTitle());
        line.getOutlinePaint().setColor(polylineOptions.getColor());
        line.setGeodesic(polylineOptions.isGeodesic());
        line.getOutlinePaint().setStrokeWidth(polylineOptions.getWidth());
        line.setSubDescription(polygonOptions.getSubtitle());
    }

    List<GeoPoint> pts = new ArrayList<>();
    for (Point point : lineString.getPoints()) {
        GeoPoint latLng = toLatLng(point);
        pts.add(latLng);
    }
    line.setPoints(pts);

    return line;
}
 
Example #5
Source File: InfoWindow.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * open the InfoWindow at the specified GeoPosition + offset.
 * If it was already opened, close it before reopening.
 *
 * @param object   the graphical object on which is hooked the view
 * @param position to place the window on the map
 * @param offsetX  (&offsetY) the offset of the view to the position, in pixels.
 *                 This allows to offset the view from the object position.
 */
public void open(Object object, GeoPoint position, int offsetX, int offsetY) {
    close(); //if it was already opened
    mRelatedObject = object;
    mPosition = position;
    mOffsetX = offsetX;
    mOffsetY = offsetY;
    onOpen(object);
    MapView.LayoutParams lp = new MapView.LayoutParams(
        MapView.LayoutParams.WRAP_CONTENT,
        MapView.LayoutParams.WRAP_CONTENT,
        mPosition, MapView.LayoutParams.BOTTOM_CENTER,
        mOffsetX, mOffsetY);

    if (mMapView != null && mView != null) {
        mMapView.addView(mView, lp);
        mIsVisible = true;
    } else {
        Log.w(IMapView.LOGTAG, "Error trapped, InfoWindow.open mMapView: " + (mMapView == null ? "null" : "ok") + " mView: " + (mView == null ? "null" : "ok"));
    }
}
 
Example #6
Source File: AnimatedMarkerTimer.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void addOverlays() {
    super.addOverlays();
    mMapView.getController().setCenter(new GeoPoint(0d, 0d));
    mMapView.getController().setZoom(5);
    mMapView.setTilesScaledToDpi(true);
    mMapView.setMapListener(this);
    mMapView.getController().setZoom(3);

    marker = new Marker(mMapView);
    marker.setPosition(new GeoPoint(45d, -74d));

    LatLonGridlineOverlay2 grids = new LatLonGridlineOverlay2();

    grids.setBackgroundColor(Color.BLACK);
    grids.setFontColor(Color.GREEN);
    grids.setLineColor(Color.GREEN);
    mMapView.getOverlayManager().add(grids);

}
 
Example #7
Source File: MapFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
/*****************************************Map event listeners****************************************************/
@Override
public boolean singleTapConfirmedHelper(GeoPoint p) {
    if (addPoiMarker) {
        if (createPoiMarker == null)
            createPoiMarker = MapUtils.addMarker(getActivity(), map, p);
        else {//move to location
            if (createPoiMarker.isInfoWindowShown())
                createPoiMarker.closeInfoWindow();
            createPoiMarker.setPosition(p);
        }
        mapPoiCreationFormContainer.setVisibility(View.VISIBLE);
    } else
        getPoiAtLocation(p.getLatitude(), p.getLongitude());
    return true;
}
 
Example #8
Source File: GeoJSONUtilTest.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessGeoJSONFeaturePolygon() {
  ShadowLog.setupLogging();
  Polygon polygon = (Polygon) GeoJSONUtil.processGeoJSONFeature(LOG_TAG, getMap(),
      alist("type", "Feature",
          "geometry", alist("type", "Polygon", "coordinates", list(list(list(-71, 42), list(-70, 42), list(-70, 41), list(-71, 42)))),
          "properties", getTestProperties()));
  assertNotNull(polygon);
  assertEquals(new GeoPoint(42.0, -71.0), polygon.getPoints().get(0).get(0));
  assertEquals(new GeoPoint(42.0, -70.0), polygon.getPoints().get(0).get(1));
  assertEquals(new GeoPoint(41.0, -70.0), polygon.getPoints().get(0).get(2));
  assertEquals(new GeoPoint(42.0, -71.0), polygon.getPoints().get(0).get(3));
  assertTestProperties(polygon);
  assertLogTriggered();
}
 
Example #9
Source File: Polyline.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * @since 6.2.0
 */
@Override
protected boolean click(final MapView pMapView, final GeoPoint pEventPos) {
    if (mOnClickListener == null) {
        return onClickDefault(this, pMapView, pEventPos);
    }
    return mOnClickListener.onClick(this, pMapView, pEventPos);
}
 
Example #10
Source File: GeometryUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
public static YailList multiPolygonToYailList(List<List<GeoPoint>> multipolygon) {
  List<YailList> result = new LinkedList<YailList>();
  for (List<GeoPoint> polygon : multipolygon) {
    result.add(pointsListToYailList(polygon));
  }
  return YailList.makeList(result);
}
 
Example #11
Source File: MainActivity.java    From spidey with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, MapView map, boolean shadow) {
	Point mapCenterPoint = new Point();
	 map.getProjection().toPixels(gp, mapCenterPoint);
	
	 GeoPoint gp2 = gp.destinationPoint(radius*30, 60);
	 Point mapCirclePoint = new Point();
	 map.getProjection().toPixels(gp2, mapCirclePoint);
	 
	int newRadius = mapCirclePoint.x - mapCenterPoint.x;
	
	// double metersPerPixel = TileSystem.GroundResolution(map.getMapCenter().getLatitude(), map.getZoomLevel());
	 
	 //int newRadius = (int)(metersPerPixel/radius);				 
	 
	 paint.setStyle(Paint.Style.STROKE);
	 paint.setColor(Color.RED);
	 paint.setStrokeWidth(5);
	 canvas.drawCircle(mapCenterPoint.x, mapCenterPoint.y, newRadius, paint);
	 
	 paint.setStyle(Paint.Style.FILL_AND_STROKE);
	 paint.setColor(Color.DKGRAY);
	 paint.setStrokeWidth(2);
	 paint.setTextSize(40);
	 canvas.drawText(label, mapCenterPoint.x, mapCenterPoint.y+newRadius, paint);
	 
}
 
Example #12
Source File: LineStringTest.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdatePoints() {
  line.updatePoints(Arrays.asList(new GeoPoint(1.0, 1.0), new GeoPoint(-1.0, -1.0)));
  YailList points = line.Points();
  assertEquals(2, points.size());
  assertEquals(1.0, ((YailList) points.get(1)).get(1));
  assertEquals(1.0, ((YailList) points.get(1)).get(2));
  assertEquals(-1.0, ((YailList) points.get(2)).get(1));
  assertEquals(-1.0, ((YailList) points.get(2)).get(2));
  assertEquals(new GeoPoint(0., 0.), line.getCentroid());
}
 
Example #13
Source File: LinearRingTest.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Test {@link LinearRing#getCenter(GeoPoint)} looping on latitudes and longitudes
 *
 * As we need to give an expected center latitude and as latitudes don't project linearly,
 * we loop through opposite latitudes, so that the expected center latitude is 0.
 *
 * We also loop in "snake" mode. Why? Doing so we avoid the "Carriage return" effect, and
 * the expected center longitude is therefore the half sum of min and max longitudes.
 * Let's say for instance that latitudes span from -10 to 10, and longitudes from -170 to 175.
 * After [latitude=-10;longitude=175], without the "snake" mode the next loop point is [-9;-170].
 * LinearRing is designed to assume that the points are as close as possible, and in that case
 * will transform [-9;-170] into [-9;190] (as it's closer to previous point [-10;175])
 * And that would have an impact on the computation of the expected center longitude.
 */
private void testGetCenter(final boolean pSeveralLatitudes, final boolean pSeveralLongitudes) {
    final int iterations = 1000;
    final double delta = 1E-10;
    final Path path = new Path();
    final GeoPoint center = new GeoPoint(0., 0);
    final LinearRing linearRing = new LinearRing(path);
    boolean increasing = true; // "snake" mode where each point is close to the previous in 2D
    for (int i = 0; i < iterations; i ++) {
        linearRing.clearPath();
        final int latitudeStop = getRandomPositiveLatitude();
        final int latitudeStart = pSeveralLatitudes ? -latitudeStop : latitudeStop; // latitudes are not projected linearly
        final int longitude1 = getRandomLongitude();
        final int longitude2 = pSeveralLongitudes ? getRandomLongitude() : longitude1;
        final int longitudeStart = Math.min(longitude1, longitude2);
        final int longitudeStop = Math.max(longitude1, longitude2);
        for (int latitude = latitudeStart ; latitude <= latitudeStop ; latitude++) {
            increasing = !increasing;
            for (int j = 0 ; j <= longitudeStop - longitudeStart ; j ++) {
                final int longitude = increasing ? longitudeStart + j : longitudeStop - j;
                linearRing.addPoint(new GeoPoint((double) latitude, longitude));
            }
        }
        linearRing.getCenter(center);
        Assert.assertEquals((latitudeStart + latitudeStop) / 2., center.getLatitude(), delta);
        Assert.assertEquals((longitudeStart + longitudeStop) / 2., center.getLongitude(), delta);
    }
}
 
Example #14
Source File: GeometryUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
public static GeoPoint pointFromYailList(YailList point) {
  if (point.length() < 3) {
    throw new DispatchableError(ErrorMessages.ERROR_INVALID_NUMBER_OF_VALUES_IN_POINT,
        2, point.length() - 1);
  }
  try {
    return GeometryUtil.coerceToPoint(point.get(1), point.get(2));
  } catch(IllegalArgumentException e) {
    throw new DispatchableError(ErrorMessages.ERROR_INVALID_POINT, point.get(1), point.get(2));
  }
}
 
Example #15
Source File: SampleGridlines.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void addOverlays() {
    super.addOverlays();
    mMapView.getController().setCenter(new GeoPoint(0d,0d));
    mMapView.getController().setZoom(5);
    mMapView.setTilesScaledToDpi(true);

    mMapView.getController().setZoom(3);

    LatLonGridlineOverlay2 grids = new LatLonGridlineOverlay2();
    mMapView.getOverlayManager().add(grids);

}
 
Example #16
Source File: NativeOpenStreetMapController.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void updateFeaturePosition(MapCircle aiCircle) {
  GeoPoint center = new GeoPoint(aiCircle.Latitude(), aiCircle.Longitude());
  Polygon polygon = (Polygon) featureOverlays.get(aiCircle);
  if (polygon != null) {
    List<GeoPoint> geopoints = Polygon.pointsAsCircle(center, aiCircle.Radius());
    polygon.setPoints(geopoints);
    view.invalidate();
  }
}
 
Example #17
Source File: LinearRing.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
protected void addGreatCircle(final GeoPoint startPoint, final GeoPoint endPoint, final int numberOfPoints) {
	//	adapted from page http://compastic.blogspot.co.uk/2011/07/how-to-draw-great-circle-on-map-in.html
	//	which was adapted from page http://maps.forum.nu/gm_flight_path.html

	// convert to radians
	final double lat1 = startPoint.getLatitude() * MathConstants.DEG2RAD;
	final double lon1 = startPoint.getLongitude() * MathConstants.DEG2RAD;
	final double lat2 = endPoint.getLatitude() * MathConstants.DEG2RAD;
	final double lon2 = endPoint.getLongitude() * MathConstants.DEG2RAD;

	final double d = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin((lat1 - lat2) / 2), 2) + Math.cos(lat1) * Math.cos(lat2)
			* Math.pow(Math.sin((lon1 - lon2) / 2), 2)));
	/*
	double bearing = Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2),
			Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2))
			/ -MathConstants.DEG2RAD;
	bearing = bearing < 0 ? 360 + bearing : bearing;
	*/

	for (int i = 1; i <= numberOfPoints; i++) {
		final double f = 1.0 * i / (numberOfPoints + 1);
		final double A = Math.sin((1 - f) * d) / Math.sin(d);
		final double B = Math.sin(f * d) / Math.sin(d);
		final double x = A * Math.cos(lat1) * Math.cos(lon1) + B * Math.cos(lat2) * Math.cos(lon2);
		final double y = A * Math.cos(lat1) * Math.sin(lon1) + B * Math.cos(lat2) * Math.sin(lon2);
		final double z = A * Math.sin(lat1) + B * Math.sin(lat2);

		final double latN = Math.atan2(z, Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
		final double lonN = Math.atan2(y, x);
		GeoPoint p = new GeoPoint(latN * MathConstants.RAD2DEG, lonN * MathConstants.RAD2DEG);
		mOriginalPoints.add(p);
	}
}
 
Example #18
Source File: Marker.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * sets the location on the planet where the icon is rendered
 * @param position
 */
public void setPosition(GeoPoint position){
	mPosition = position.clone();
	if (isInfoWindowShown()) {
		closeInfoWindow();
		showInfoWindow();
	}
	mBounds=new BoundingBox(position.getLatitude(),position.getLongitude(),position.getLatitude(),position.getLongitude());
}
 
Example #19
Source File: WeathForceActivity.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_starter_mapview);

    Intent intent = getIntent();
    //if (intent)
    final double lat1 = 25.633;
    final double long1 = 71.094;

    //super important. Many tile servers, including open street maps, will BAN applications by user
    //agent. Do not use the sample application's user agent for your app! Use your own setting, such
    //as the app id.
    Configuration.getInstance().setUserAgentValue(getPackageName());

    mMapView = findViewById(R.id.mapview);
    mMapView.setTileSource(TileSourceFactory.MAPNIK);


    mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this),
            mMapView);
    mCompassOverlay.enableCompass();
    mMapView.getOverlays().add(this.mCompassOverlay);

    addOverlays();

    GeoPoint startPoint = new GeoPoint(lat1, long1);
    IMapController mapController = mMapView.getController();
    mapController.setZoom(9);
    mapController.setCenter(startPoint);
    Marker startMarker = new Marker(mMapView);
    startMarker.setPosition(startPoint);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    mMapView.getOverlays().add(startMarker);


    mMapView.invalidate();

}
 
Example #20
Source File: GeoHelper.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public static ArrayList<Intent> createGeoIntentsFromMessage(Context context, Message message) {
    final ArrayList<Intent> intents = new ArrayList<>();
    final GeoPoint geoPoint;
    try {
        geoPoint = parseGeoPoint(message.getBody());
    } catch (IllegalArgumentException e) {
        return intents;
    }
    final Conversational conversation = message.getConversation();
    final String label = getLabel(context, message);

    Intent locationPluginIntent = new Intent(context, ShowLocationActivity.class);
    locationPluginIntent.putExtra("latitude", geoPoint.getLatitude());
    locationPluginIntent.putExtra("longitude", geoPoint.getLongitude());
    if (message.getStatus() != Message.STATUS_RECEIVED) {
        locationPluginIntent.putExtra("jid", conversation.getAccount().getJid().toString());
        locationPluginIntent.putExtra("name", context.getString(R.string.me));
    } else {
        Contact contact = message.getContact();
        if (contact != null) {
            locationPluginIntent.putExtra("name", contact.getDisplayName());
            locationPluginIntent.putExtra("jid", contact.getJid().toString());
        } else {
            locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart()));
        }
    }
    intents.add(locationPluginIntent);

    Intent geoIntent = new Intent(Intent.ACTION_VIEW);
    geoIntent.setData(Uri.parse("geo:" + String.valueOf(geoPoint.getLatitude()) + "," + String.valueOf(geoPoint.getLongitude()) + "?q=" + String.valueOf(geoPoint.getLatitude()) + "," + String.valueOf(geoPoint.getLongitude()) + label));
    intents.add(geoIntent);
    return intents;
}
 
Example #21
Source File: AnimatedMarkerTypeEvaluator.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.btnCache:
            if (valueAnimator!=null && valueAnimator.isRunning())
                valueAnimator.cancel();
            GeoPoint random = new GeoPoint((Math.random() * 180) - 90, (Math.random() * 360) - 180);
            valueAnimator = MarkerAnimation.animateMarkerToICS(mMapView,marker, random, new GeoPointInterpolator.Spherical());
            break;
    }
}
 
Example #22
Source File: GeoJSONUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private void writePointGeometry(GeoPoint point) {
  out.print("\"geometry\":{\"type\":\"Point\",\"coordinates\":[");
  out.print(point.getLongitude());
  out.print(",");
  out.print(point.getLatitude());
  if (hasAltitude(point)) {
    out.print(",");
    out.print(point.getAltitude());
  }
  out.print("]}");
}
 
Example #23
Source File: ScaleDiskOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
public ScaleDiskOverlay(final Context pContext,
						final GeoPoint pGeoCenter,
						final int pValue, final GeoConstants.UnitOfMeasure pUnitOfMeasure) {
	mGeoCenter = pGeoCenter;
	mMeters = pValue * pUnitOfMeasure.getConversionFactorToMeters();
	mLabel = ScaleBarOverlay.getScaleString(
			pContext,
			String.format(Locale.getDefault(), "%d", pValue), pUnitOfMeasure);
}
 
Example #24
Source File: GroundOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
public void setPosition(final GeoPoint pTopLeft, final GeoPoint pTopRight,
                        final GeoPoint pBottomRight, final GeoPoint pBottomLeft) {
    mMatrix.reset();
    mTopLeft = new GeoPoint(pTopLeft);
    mTopRight = new GeoPoint(pTopRight);
    mBottomRight = new GeoPoint(pBottomRight);
    mBottomLeft = new GeoPoint(pBottomLeft);
    mBounds= new BoundingBox(pTopLeft.getLatitude(),pTopRight.getLongitude(),
        pBottomRight.getLatitude(),pTopLeft.getLongitude()
        );
}
 
Example #25
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 #26
Source File: DataCountry.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
public DataCountry(final String pISO3166_1_alpha_3, final String pName,
                   final String pCapitalName,
                   final double pCapitalLatitude, final double pCapitalLongitude) {
    mISO3166_1_alpha_3 = pISO3166_1_alpha_3;
    mName = pName;
    mCapitalName = pCapitalName;
    mCapitalGeoPoint = new GeoPoint(pCapitalLatitude, pCapitalLongitude);
}
 
Example #27
Source File: AnimatedMarkerValueAnimator.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.btnCache:
            if (valueAnimator!=null && valueAnimator.isRunning())
                valueAnimator.cancel();
            GeoPoint random = new GeoPoint((Math.random() * 180) - 90, (Math.random() * 360) - 180);
            valueAnimator = MarkerAnimation.animateMarkerToHC(mMapView,marker, random, new GeoPointInterpolator.Spherical());
            break;
    }
}
 
Example #28
Source File: Bug82WinDeath.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
protected void addOverlays() {
    //
    MapOverlay overlay = new MapOverlay();
    overlay.setEnabled(true);
    mMapView.getOverlayManager().add(overlay);
    mMapView.getController().setCenter(new GeoPoint(50.71838, -103.42443));
    mMapView.getController().setZoom(17);
}
 
Example #29
Source File: GeometryUtilTest.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMidpointLineString2() {
  List<GeoPoint> points = new ArrayList<GeoPoint>();
  points.add(new GeoPoint(0.0, 0.0));
  points.add(new GeoPoint(0.0, 2.0));
  GeoPoint result = GeometryUtil.getMidpoint(points);
  assertNotNull(result);
  assertEquals(0.0, result.getLatitude(), TOLERANCE);
  assertEquals(1.0, result.getLongitude(), TOLERANCE);
}
 
Example #30
Source File: MapView.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Deferred setting of the expected next map center computed by the Projection's constructor,
 * with no guarantee it will be 100% respected.
 * <a href="https://github.com/osmdroid/osmdroid/issues/868">see issue 868</a>
 * @since 6.0.3
 */
public void setExpectedCenter(final IGeoPoint pGeoPoint, final long pOffsetX, final long pOffsetY) {
    final GeoPoint before = getProjection().getCurrentCenter();
	mCenter = (GeoPoint)pGeoPoint;
	setMapScroll(-pOffsetX, -pOffsetY);
	resetProjection();
       final GeoPoint after = getProjection().getCurrentCenter();
       if (!after.equals(before)) {
       	ScrollEvent event = null;
		for (MapListener mapListener: mListners) {
			mapListener.onScroll(event != null ? event : (event = new ScrollEvent(this, 0, 0)));
		}
	}
	invalidate();
}