super.draw(canvas, mapv, shadow); Paint mPaint = new Paint(); mPaint.setDither(true); mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeWidth(2); GeoPoint gP1 = new GeoPoint(19240000,-99120000); GeoPoint gP2 = new GeoPoint(37423157, -122085008); Point p1 = new Point(); Point p2 = new Point(); Path path = new Path(); Projection projection=mapv.getProjection(); projection.toPixels(gP1, p1); projection.toPixels(gP2, p2); canvas.drawPath(path, mPaint);
private void handleGeoBoundsAggregation(List<String> headers, List<List<Object>> lines, GeoBounds geoBoundsAggregation) { String geoBoundAggName = geoBoundsAggregation.getName(); headers.add(geoBoundAggName + ".topLeft.lon"); headers.add(geoBoundAggName + ".topLeft.lat"); headers.add(geoBoundAggName + ".bottomRight.lon"); headers.add(geoBoundAggName + ".bottomRight.lat"); List<Object> line = lines.get(this.currentLineIndex); line.add(String.valueOf(geoBoundsAggregation.topLeft().getLon())); line.add(String.valueOf(geoBoundsAggregation.topLeft().getLat())); line.add(String.valueOf(geoBoundsAggregation.bottomRight().getLon())); line.add(String.valueOf(geoBoundsAggregation.bottomRight().getLat())); lines.add(line); }
int minLat = Integer.MAX_VALUE; int maxLat = Integer.MIN_VALUE; int minLon = Integer.MAX_VALUE; int maxLon = Integer.MIN_VALUE; for (GeoPoint item : items) { int lat = item.getLatitudeE6(); int lon = item.getLongitudeE6(); maxLat = Math.max(lat, maxLat); minLat = Math.min(lat, minLat); maxLon = Math.max(lon, maxLon); minLon = Math.min(lon, minLon); } mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon)); mapController.animateTo(new GeoPoint( (maxLat + minLat)/2, (maxLon + minLon)/2 ));
public class OsmdroidDemoMap extends Activity { private MapView mMapView; private MapController mMapController; int mIncr = 10000; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.osm_main); mMapView = (MapView) findViewById(R.id.mapview); mMapView.setTileSource(TileSourceFactory.MAPNIK); mMapView.setBuiltInZoomControls(true); mMapView.setMultiTouchControls(true); mMapController = mMapView.getController(); mMapController.setZoom(13); GeoPoint gPt0 = new GeoPoint(51500000, -150000); GeoPoint gPt1 = new GeoPoint(gPt0.getLatitudeE6()+ mIncr, gPt0.getLongitudeE6()); GeoPoint gPt2 = new GeoPoint(gPt0.getLatitudeE6()+ mIncr, gPt0.getLongitudeE6() + mIncr); GeoPoint gPt3 = new GeoPoint(gPt0.getLatitudeE6(), gPt0.getLongitudeE6() + mIncr); mMapController.setCenter(gPt0); PathOverlay myPath = new PathOverlay(Color.RED, this); myPath.addPoint(gPt0); myPath.addPoint(gPt1); myPath.addPoint(gPt2); myPath.addPoint(gPt3); myPath.addPoint(gPt0); mMapView.getOverlays().add(myPath); } }
mMapController.setZoom(18); GeoPoint point1 = new GeoPoint(19240000,-99120000); GeoPoint point2 = new GeoPoint(19241000,-99121000); mMapController.setCenter(point2); super.draw(canvas, mapView, shadow); Paint paint; paint = new Paint(); paint.setColor(Color.RED); paint.setAntiAlias(true); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); Point pt1 = new Point(); Point pt2 = new Point(); Projection projection = mapView.getProjection(); projection.toPixels(mGpt1, pt1); projection.toPixels(mGpt2, pt2); canvas.drawLine(pt1.x, pt1.y, pt2.x, pt2.y, paint); return true;
myMapView = (MapView) findViewById(R.id.mapview); geoPoint = null; myMapView.setSatellite(false); GeoPoint startGP = new GeoPoint( (int) (Double.parseDouble(lngLat[1]) * 1E6), (int) (Double .parseDouble(lngLat[0]) * 1E6)); myMC = myMapView.getController(); geoPoint = startGP; myMC.setCenter(geoPoint); myMC.setZoom(15); myMapView.getOverlays().add(new DirectionPathOverlay(startGP, startGP)); gp2 = new GeoPoint((int) (Double.parseDouble(lngLat[1]) * 1E6), (int) (Double.parseDouble(lngLat[0]) * 1E6)); myMapView.getOverlays().add(new DirectionPathOverlay(gp1, gp2)); if (shadow == false) {
Projection projection = mapView.getProjection(); Point pt = new Point(); GeoPoint geo = new GeoPoint((int) (mLat *1e6), (int)(mLon * 1e6)); projection.toPixels(geo ,pt); float circleRadius = projection.metersToEquatorPixels(mRadius) * (1/ FloatMath.cos((float) Math.toRadians(mLat))); innerCirclePaint = new Paint(); innerCirclePaint.setColor(Color.BLUE); innerCirclePaint.setAlpha(25); innerCirclePaint.setAntiAlias(true); innerCirclePaint.setStyle(Paint.Style.FILL); canvas.drawCircle((float)pt.x, (float)pt.y, circleRadius, innerCirclePaint);
@Override public void draw(Canvas canvas, MapView mapView, boolean shadow/*, long when*/) { super.draw(canvas, mapView, shadow); Paint paint = new Paint(); // Converts lat/lng-Point to OUR coordinates on the screen. android.graphics.Point myScreenCoords = new android.graphics.Point(); GeoPoint point = new GeoPoint(15340000,75120000); mapView.getProjection().toPixels(point, myScreenCoords); paint.setStrokeWidth(1); paint.setARGB(255, 255, 255, 255); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(20); paint.setColor(Color.RED); paint.setStrokeWidth(2); canvas.drawText("Here I am...", myScreenCoords.x-10,myScreenCoords.y-48, paint); return true; }
super.draw(canvas, mapv, shadow); Projection projection = mapv.getProjection(); //Add this line mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.FILL); mPaint.setAlpha(100); GeoPoint gP1 = new GeoPoint(32733839,-97112976); GeoPoint gP2 = new GeoPoint(32733875, -97113448); GeoPoint gP3 = new GeoPoint(32734961,-97113455); GeoPoint gP4 = new GeoPoint(32734953, -97112962); Point p1 = new Point(); Point p2 = new Point(); Point p3 = new Point(); Point p4 = new Point(); Path path = new Path(); projection.toPixels(gP1, p1); projection.toPixels(gP2, p2); projection.toPixels(gP3, p3); projection.toPixels(gP4, p4); path.lineTo(p4.x,p4.y); canvas.drawPath(path, mPaint);
class MarkerOverlay extends com.google.android.maps.Overlay { //create a constructor here with p.x and p.y as parameters @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); Point screenPts = new Point(); Bitmap bmp = BitmapFactory.decodeResource( getResources(), R.drawable.pushpin); GeoPoint point = new GeoPoint( (int) (p.x * 1E6), (int) (p.y * 1E6)); mapView.getProjection().toPixels(point, screenPts); canvas.drawBitmap(bmp, screenPts.x-16, screenPts.y-32, null); canvas.drawText(parts[0],screenPts.x-16 , screenPts.y-40, new Paint()); } } } return true; } }
Point screenPts = new Point(); @Override protected void drawOverlayBitmap(Canvas canvas, Point point, Projection projection, byte zoom){ projection.toPixels(new GeoPoint((int)(location.getLatitude()*1E6), (int)(location.getLongitude()*1E6)) , screenPts); canvas.drawBitmap(myBitmap, screenPts.x, screenPts.y, new Paint()); }
@Override public void draw(Canvas canvas, MapView mapview, boolean shadow) { super.draw(canvas, mapview, shadow); if(location != null){ //---translate the GeoPoint with center to screen pixels--- screenPts = new Point(); mapview.getProjection().toPixels(new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6)) , screenPts); //Draw accuracy marker GeoPoint g0 = mapview.getProjection().fromPixels(0, screenPts.y); GeoPoint g1 = mapview.getProjection().fromPixels(width, screenPts.y); l0.setLatitude(g0.getLatitudeE6()/1E6); l0.setLongitude(g0.getLongitudeE6()/1E6); l1.setLatitude(g1.getLatitudeE6()/1E6); l1.setLongitude(g1.getLongitudeE6()/1E6); float d01=l0.distanceTo(l1); int size=(int)(location.getAccuracy() * width / d01); canvas.drawCircle(screenPts.x, screenPts.y, size, paintAccuracyFill); canvas.drawCircle(screenPts.x, screenPts.y, size, paintAccuracyStroke); } }
public class MyOverlay extends SimpleLocationOverlay{ private MyCar myCar = new MyCar(); private GeoPoint geoPosition = new GeoPoint(0, 0); private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); public myOverlay(Context ctx) { super(ctx); // TODO Auto-generated constructor stub } public myOverlay(Context ctx, MyCar _myCar) { super(ctx); this.myCar= _myCar; this.paint.setAntiAlias(true); ... } @Override public void draw(Canvas c, MapView osmv, boolean shadow) { Point mapCenterPoint = new Point(); osmv.getProjection().toPixels(this.geoPosition, mapCenterPoint); c.drawCircle(mapCenterPoint.x, mapCenterPoint.y, 10, this.paint); } }
final GeoPoint geoPointUL = new GeoPoint( (int) (Mercator.tile2lat(y, zoomLevel) * 1E6), (int) (Mercator.tile2lon(x, zoomLevel) * 1E6)); final GeoPoint geoPointLR = new GeoPoint( (int) (Mercator.tile2lat(y+1, zoomLevel) * 1E6), (int) (Mercator.tile2lon(x+1, zoomLevel) * 1E6)); Point pointUL=new Point(), pointLR=new Point(); pj.toPixels(geoPointUL, pointUL); pj.toPixels(geoPointLR, pointLR); tileSizePx = pointLR.x - pointUL.x;
private ImageView mCurrentPointer; @Override public void onLocationChanged(Location l) { int latitude = (int) (l.getLatitude() * 1e6); int longitude = (int) (l.getLongitude() * 1e6); // Prepare new LayoutParams object that centers on our new latitude/longitude MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT, new GeoPoint(latitude, longitude), MapView.LayoutParams.CENTER); if (mCurrentPointer == null) { // If "current location" pin is null, we haven't added it // to MapView yet. So instantiate it and add it to MapView: mCurrentPointer = new ImageView(this); mCurrentPointer.setImageResource(R.drawable.ic_maps_indicator_current_position); mMapView.addView(mCurrentPointer, lp); } else { // If it's already added, just update its location mCurrentPointer.setLayoutParams(lp); } }
GeoPoint spare = new GeoPoint(); if (fields.length == 0) { IndexableField[] lonFields = document.getFields(fieldName + ".lon"); spare.reset(latField.numericValue().doubleValue(), lonField.numericValue().doubleValue()); geohashes.add(stringEncode(spare.getLon(), spare.getLat(), precision)); for (IndexableField field : fields) { if (field instanceof StringField) { spare.resetFromString(field.stringValue()); geohashes.add(spare.geohash()); } else if (field instanceof LatLonPoint || field instanceof LatLonDocValuesField) { spare.resetFromIndexableField(field); geohashes.add(spare.geohash());
mapView.setBuiltInZoomControls(true); urlString.append("http://maps.google.com/maps?f=d&hl=en"); urlString.append("&saddr=");//from urlString.append( Double.toString(lastKnownLocation.getLatitude() )); urlString.append(","); urlString.append( Double.toString(lastKnownLocation.getLongitude() )); urlString.append("&daddr=");//to urlString.append( Double.toString((double)dest[0]/1.0E6 )); GeoPoint currentPoint = new GeoPoint( new Double(lastKnownLocation.getLatitude()*1E6).intValue() ,new Double(lastKnownLocation.getLongitude()*1E6).intValue() ); MapController mc = mapView.getController(); mc.zoomToSpan(bgItemizedOverlay.getLatSpanE6()*2,bgItemizedOverlay.getLonSpanE6()*2); mc.animateTo(new GeoPoint( (currentPoint.getLatitudeE6() + destPoint.getLatitudeE6()) / 2 , (currentPoint.getLongitudeE6() + destPoint.getLongitudeE6()) / 2));
float lat = -23.4456f; float lng = 45.44334f; GeoPoint gp = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));