@Override public void getMapScreenBounds(OnMapBoundsCallback callback) { final Projection projection = googleMap.getProjection(); int hOffset = getResources().getDimensionPixelOffset(R.dimen.map_horizontal_padding); int vOffset = getResources().getDimensionPixelOffset(R.dimen.map_vertical_padding); LatLngBounds.Builder builder = LatLngBounds.builder(); builder.include(projection.fromScreenLocation(new Point(hOffset, vOffset))); // top-left builder.include(projection.fromScreenLocation( new Point(getView().getWidth() - hOffset, vOffset))); // top-right builder.include(projection.fromScreenLocation( new Point(hOffset, getView().getHeight() - vOffset))); // bottom-left builder.include(projection.fromScreenLocation(new Point(getView().getWidth() - hOffset, getView().getHeight() - vOffset))); // bottom-right callback.onMapBoundsReady(builder.build()); }
@Override public void getScreenLocation(LatLng latLng, OnLatLngScreenLocationCallback callback) { callback.onLatLngScreenLocationReady(googleMap.getProjection().toScreenLocation(latLng)); }
@Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { Projection proj = mapView.getProjection(); GeoPoint loc = new GeoPoint(geo.getLat(), geo.getLng()); Point point = new Point(); proj.toPixels(loc, point); float rad = (float) (proj.metersToEquatorPixels(radius) * (1 / Math.cos(Math.toRadians(loc.getLatitudeE6() / 1000000)))); Paint circle = new Paint(); circle.setColor(colour); circle.setAlpha(30); circle.setAntiAlias(true); circle.setStyle(Style.FILL); canvas.drawCircle(point.x, point.y, rad, circle); super.draw(canvas, mapView, shadow); }
GeoPoint gp2 = route[i + 1]; polyPaint.setAntiAlias(true); Point point = new Point(); projection.toPixels(gp1, point); Point point2 = new Point(); projection.toPixels(gp2, point2); + mRadius); offscreencanvas.drawOval(oval, polyPaint); Point point2 = new Point(); projection.toPixels(gp2, point2); path.lineTo(point2.x, point2.y); Point point2 = new Point(); projection.toPixels(gp2, point2); path.lineTo(point2.x, point2.y); mapStartPosition = projection.fromPixels(0, 0); Point offsetPt = new Point(); proj.toPixels(mapStartPosition, offsetPt);
point = new GeoPoint((int)(latitude),(int)(longitude)); OverlayItem overlayitem = new OverlayItem(point, "Radius", String.format("%.0f m", accuracy)); itemizedoverlay.addOverlay(overlayitem); int latSpan, longSpan, rightEdge, leftEdge, topEdge, bottomEdge; boolean setIsIn, userIsIn; center = new GeoPoint((point.getLatitudeE6() + userLocationOverlay.getMyLocation().getLatitudeE6())/2,(point.getLongitudeE6() + point.getLongitudeE6())/2); centerLatitude = center.getLatitudeE6(); centerLongitude = center.getLongitudeE6(); Point pt = new Point(); projection.toPixels(point ,pt); float circleRadius = projection.metersToEquatorPixels((float)accuracy); innerCirclePaint = new Paint(); innerCirclePaint.setColor(Color.BLUE); innerCirclePaint.setAlpha(25); innerCirclePaint.setAntiAlias(true); CirclePaint.setAntiAlias(true); canvas.drawCircle((float)pt.x, (float)pt.y, circleRadius, innerCirclePaint);
private void drawCircleAtPoint(GeoPoint point, Canvas canvas, MapView mapView) { Projection projection = mapView.getProjection(); Point pt2 = new Point(); projection.toPixels(point, pt2); // method that is used to conver the radius to pixel that takes input the radius and draw it on the coresponding pixels float circleRadius = projection.metersToEquatorPixels(radius) * (1/ FloatMath.cos((float) Math.toRadians(MapController.mylat))); Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); Paint rectangle=new Paint(Paint.ANTI_ALIAS_FLAG); Log.d("Circular Radius", ""+circleRadius+" "+radius); circlePaint.setColor(0x99000000); circlePaint.setStyle(Style.STROKE); canvas.drawCircle((float)pt2.x, (float)pt2.y, circleRadius, circlePaint); }
Projection projection = mapView.getProjection(); Point center = projection.toPixels(new GeoPoint(yourLat * E6, yourLong * E6), null); float radius = projection.metersToEquatorPixels(radiusInMeters); canvas.draw(center.x, center.y, radius, new Paint());
Point p = new Point(); projection.toPixels(point11, p); p.offset(0, -(bubble.getMeasuredHeight() / 2)); GeoPoint target = projection.fromPixels(p.x, p.y);
public static void panMap (int x, int y, MapView map) { Point ptPixels = new Point(); GeoPoint geoPt = map.getMapCenter(); Projection projection = map.getProjection(); projection.toPixels(geoPt, ptPixels); ptPixels.x += x; ptPixels.y += y; geoPt = projection.fromPixels(ptPixels.x, ptPixels.y); map.getController().animateTo(geoPt); }
@Override public void draw(Canvas canvas, MapView mapview, boolean shadow) { super.draw(canvas, mapview, shadow); if(shadow) return; if(mp.getPoints() == null || mp.getPoints().size() < 2) return; Projection projection = mapview.getProjection(); int lonSpanNew = projection.fromPixels(0,mapview.getHeight()/2).getLongitudeE6() - projection.fromPixels(mapview.getWidth(),mapview.getHeight()/2).getLongitudeE6(); if(lonSpanNew != pathInitialLonSpan) pathBuild(); else{ //check if path need to be offset projection.toPixels(mp.getPoints().get(0), p1); if(p1.x != pathInitialPoint.x || p1.y != pathInitialPoint.y){ path.offset(p1.x - pathInitialPoint.x, p1.y - pathInitialPoint.y); pathInitialPoint.x = p1.x; pathInitialPoint.y = p1.y; } } canvas.drawPath(path, paint); }
Point mapCenter = projection.toPixels(getMapCenter(), null); Point newCenter = new Point(mapCenter); if (!newCenter.equals(mapCenter)) { getController().animateTo(projection.fromPixels(newCenter.x, newCenter.y));
private double calculateDistanceBetweenMarkers() { Projection projection = map.getProjection(); Point point = projection.toScreenLocation(new LatLng(0.0, 0.0)); point.x += getResources().getDimensionPixelSize(R.dimen.distance_between_markers); LatLng nextPosition = projection.fromScreenLocation(point); return nextPosition.longitude; }
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 = 500; final Interpolator interpolator = new LinearInterpolator(); long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.getLongitude() + (1 - t) * startGeoPoint.getLongitude(); double lat = t * toPosition.getLatitude() + (1 - t) * startGeoPoint.getLatitude(); marker.setPosition(new GeoPoint(lat, lng)); if (t < 1.0) { handler.postDelayed(this, 15);
@Override public VisibleRegion getVisibleRegion() { return projection.getVisibleRegion(); }
Projection projection = map.getProjection(); projection.toPixels(geoPointBefore, pt); geoPointAfter = projection.fromPixels(pt.x, pt.y); int diffLatitude = geoPointBefore.getLatitudeE6() - geoPointAfter.getLatitudeE6(); int diffLongitude = geoPointBefore.getLongitudeE6() - geoPointAfter.getLongitudeE6(); ... ... ... // Add the difference to GeoPoint objects after conversion `fromPixels`
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); 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);
Point p = new Point(); projection.toPixels(result.getPoint(), p); p.offset(0, -(bubble.getMeasuredHeight() / 2)); GeoPoint target = projection.fromPixels(p.x, p.y);
@Override public void draw(Canvas canvas, MapView mapview, boolean shadow) { super.draw(canvas, mapview, shadow); if(shadow) return; if(mp.getPoints() == null || mp.getPoints().size() < 2) return; Projection projection = mapview.getProjection(); int lonSpanNew = projection.fromPixels(0,mapview.getHeight()/2).getLongitudeE6() - projection.fromPixels(mapview.getWidth(),mapview.getHeight()/2).getLongitudeE6(); if(lonSpanNew != pathInitialLonSpan) pathBuild(); else{ //check if path need to be offset projection.toPixels(mp.getPoints().get(0), p1); if(p1.x != pathInitialPoint.x || p1.y != pathInitialPoint.y){ path.offset(p1.x - pathInitialPoint.x, p1.y - pathInitialPoint.y); pathInitialPoint.x = p1.x; pathInitialPoint.y = p1.y; } } canvas.drawPath(path, paint); }
@Override public void onPageSelected(int position) { MyLocation location = latLngsArrayList.get(position); Point mappoint = map.getProjection().toScreenLocation( new LatLng(location.getLatitude(), location.getLongitude())); mappoint.set(mappoint.x, mappoint.y - 30); map.animateCamera(CameraUpdateFactory.newLatLng(map.getProjection().fromScreenLocation(mappoint))); customMap.addSelectedCustomPin(position); }
@Override public VisibleRegion getVisibleRegion() { return AnyMapAdapter.adapt(projection.getVisibleRegion()); }