com.google.android.maps.Projection

Here are the examples of the java api class com.google.android.maps.Projection taken from open source projects.

1. MapViewUtils#smoothScrollBy()

Project: Polaris
File: MapViewUtils.java
/**
     * Animated equivalent to {@link MapController#scrollBy(int, int)}. Scroll
     * by a given amount using the default animation, in pixels.
     * <p>
     * <strong>Limitations</strong>: This method internally uses
     * {@link MapController#animateTo(com.google.android.maps.GeoPoint)} which
     * doesn't animate anything if the point is really far (in pixels) from the
     * current point. In this case, nothing will be animated at all.
     * 
     * @param mapView The {@link MapView} to scroll
     * @param dx The horizontal scroll amount in pixels.
     * @param dy The vertical scroll amount in pixels.
     */
public static void smoothScrollBy(MapView mapView, int dx, int dy) {
    final Projection projection = mapView.getProjection();
    final Point tmpPoint = TEMP_POINT;
    projection.toPixels(mapView.getMapCenter(), tmpPoint);
    tmpPoint.offset(dx, dy);
    mapView.getController().animateTo(projection.fromPixels(tmpPoint.x, tmpPoint.y));
}

2. MixMap#draw()

Project: mixare
File: MixMap.java
public void draw(Canvas canvas, MapView mapv, boolean shadow) {
    super.draw(canvas, mapv, shadow);
    if (geoPoints.size() <= 0) {
        return;
    }
    Projection projection = mapv.getProjection();
    Paint mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setColor(Color.BLUE);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(3);
    Path path = new Path();
    Point start = new Point();
    projection.toPixels(geoPoints.get(0), start);
    path.moveTo(start.x, start.y);
    for (GeoPoint gp : geoPoints) {
        Point p = new Point();
        projection.toPixels(gp, p);
        path.lineTo(p.x, p.y);
    }
    canvas.drawPath(path, mPaint);
}

3. AccuracyCircleOverlay#draw()

Project: ignition
File: AccuracyCircleOverlay.java
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    Projection projection = mapView.getProjection();
    if (shadow && projection == null) {
        Log.v(LOG_TAG, "drawing not done because shadow and projection are null");
        return;
    }
    Point pt = new Point();
    projection.toPixels(geoPoint, pt);
    float circleRadius = metersToRadius(accuracy, projection, geoPoint.getLatitudeE6());
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(0x186666ff);
    paint.setStyle(Style.FILL_AND_STROKE);
    canvas.drawCircle(pt.x, pt.y, circleRadius, paint);
    paint.setColor(0xff6666ff);
    paint.setStyle(Style.STROKE);
    canvas.drawCircle(pt.x, pt.y, circleRadius, paint);
    paint.setColor(Color.RED);
    paint.setStyle(Style.FILL_AND_STROKE);
    canvas.drawCircle(pt.x, pt.y, 3, paint);
    super.draw(canvas, mapView, shadow);
}

4. GoogleTilesOverlay#draw()

Project: osmdroid
File: GoogleTilesOverlay.java
@Override
public void draw(final Canvas c, final MapView osmv, final boolean shadow) {
    if (DEBUGMODE) {
        Log.d(Constants.LOGTAG, "draw");
    }
    // Calculate the half-world size
    final Projection pj = osmv.getProjection();
    final int zoomLevel = osmv.getZoomLevel() - 1;
    final int tileSizePx = this.mTileProvider.getTileSource().getTileSizePixels();
    // Calculate the tiles needed for each side around the center one.
    final int latSpan = osmv.getLatitudeSpan();
    final int longSpan = osmv.getLongitudeSpan();
    final int topLatitude = osmv.getMapCenter().getLatitudeE6() + latSpan / 2;
    final int leftLongitude = osmv.getMapCenter().getLongitudeE6() - longSpan / 2;
    final int bottomLatitude = osmv.getMapCenter().getLatitudeE6() - latSpan / 2;
    final int rightLongitude = osmv.getMapCenter().getLongitudeE6() + longSpan / 2;
    final Point leftTopXY = Mercator.projectGeoPoint(topLatitude * 1E-6, leftLongitude * 1E-6, zoomLevel, new Point(0, 0));
    final Point rightBottomXY = Mercator.projectGeoPoint(bottomLatitude * 1E-6, rightLongitude * 1E-6, zoomLevel, new Point(0, 0));
    final int tileNeededAtLeft = leftTopXY.x;
    final int tileNeededAtRight = rightBottomXY.x;
    final int tileNeededAtTop = leftTopXY.y;
    final int tileNeededAtBottom = rightBottomXY.y;
    final int mapTileUpperBound = 1 << zoomLevel;
    // make sure the cache is big enough for all the tiles
    final int numNeeded = (tileNeededAtBottom - tileNeededAtTop + 1) * (tileNeededAtRight - tileNeededAtLeft + 1);
    mTileProvider.ensureCapacity(numNeeded);
    /* Draw all the MapTiles (from the upper left to the lower right). */
    for (int y = tileNeededAtTop; y <= tileNeededAtBottom; y++) {
        for (int x = tileNeededAtLeft; x <= tileNeededAtRight; x++) {
            // Construct a MapTile to request from the tile provider.
            final int tileY = MyMath.mod(y, mapTileUpperBound);
            final int tileX = MyMath.mod(x, mapTileUpperBound);
            final MapTile tile = new MapTile(zoomLevel, tileX, tileY);
            final Drawable currentMapTile = mTileProvider.getMapTile(tile);
            if (currentMapTile != null) {
                final GeoPoint gp = new GeoPoint((int) (Mercator.tile2lat(y, zoomLevel) * 1E6), (int) (Mercator.tile2lon(x, zoomLevel) * 1E6));
                pj.toPixels(gp, mTilePos);
                mTileRect.set(mTilePos.x, mTilePos.y, mTilePos.x + tileSizePx, mTilePos.y + tileSizePx);
                currentMapTile.setBounds(mTileRect);
                currentMapTile.draw(c);
            }
            if (DEBUGMODE) {
                c.drawText(tile.toString(), mTileRect.left + 1, mTileRect.top + mPaint.getTextSize(), mPaint);
                c.drawLine(mTileRect.left, mTileRect.top, mTileRect.right, mTileRect.top, mPaint);
                c.drawLine(mTileRect.left, mTileRect.top, mTileRect.left, mTileRect.bottom, mPaint);
            }
        }
    }
    // draw a cross at center in debug mode
    if (DEBUGMODE) {
        final GeoPoint center = osmv.getMapCenter();
        final Point centerPoint = pj.toPixels(center, null);
        c.drawLine(centerPoint.x, centerPoint.y - 9, centerPoint.x, centerPoint.y + 9, mPaint);
        c.drawLine(centerPoint.x - 9, centerPoint.y, centerPoint.x + 9, centerPoint.y, mPaint);
    }
}

5. GooglePolylineOverlay#draw()

Project: osmdroid
File: GooglePolylineOverlay.java
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    if (shadow) {
        return;
    }
    final int size = mPoints.size();
    if (size < 2) {
        // nothing to paint
        return;
    }
    final Projection pj = mapView.getProjection();
    // points on screen
    Point screenPoint0 = null;
    Point screenPoint1;
    // points from the points list
    GeoPoint projectedPoint0;
    GeoPoint projectedPoint1;
    mPath.rewind();
    projectedPoint0 = mPoints.get(size - 1);
    for (int i = size - 2; i >= 0; i--) {
        // compute next points
        projectedPoint1 = mPoints.get(i);
        // bounds
        if (screenPoint0 == null) {
            screenPoint0 = pj.toPixels(projectedPoint0, mTempPoint1);
            mPath.moveTo(screenPoint0.x, screenPoint0.y);
        }
        screenPoint1 = pj.toPixels(projectedPoint1, mTempPoint2);
        // skip this point, too close to previous point
        if (Math.abs(screenPoint1.x - screenPoint0.x) + Math.abs(screenPoint1.y - screenPoint0.y) <= 1) {
            continue;
        }
        mPath.lineTo(screenPoint1.x, screenPoint1.y);
        // update starting point to next position
        projectedPoint0 = projectedPoint1;
        screenPoint0.x = screenPoint1.x;
        screenPoint0.y = screenPoint1.y;
    }
    canvas.drawPath(mPath, mPaint);
}