Java Code Examples for com.google.android.gms.maps.Projection#toScreenLocation()

The following examples show how to use com.google.android.gms.maps.Projection#toScreenLocation() . 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: RichPolygon.java    From richmaps with Apache License 2.0 6 votes vote down vote up
protected void drawHole(final Bitmap bitmap, final Projection projection,
                        final List<RichPoint> points2Draw,
                        final int paddingLeft, final int paddingTop,
                        final int paddingRight, final int paddingBottom) {
    Canvas canvas = new Canvas(bitmap);
    Path linePath = new Path();
    boolean firstPoint = true;
    for (RichPoint point : points2Draw) {
        LatLng position = point.getPosition();
        if (position != null) {
            Point bmpPoint = projection.toScreenLocation(position);
            int bmpPointX = bmpPoint.x;
            int bmpPointY = bmpPoint.y + paddingBottom / 2 - paddingTop / 2;

            if (firstPoint) {
                linePath.moveTo(bmpPointX, bmpPointY);
                firstPoint = false;
            } else {
                linePath.lineTo(bmpPointX, bmpPointY);
            }
        }
    }

    Paint paint = getDefaultHolePaint();
    canvas.drawPath(linePath, paint);
}
 
Example 2
Source File: MyView.java    From mil-sym-android with Apache License 2.0 6 votes vote down vote up
private void ptsGeoToPixels() {
    _points.clear();
    int j = 0;
    LatLng ptGeo = null;
    double longitude = 0;
    double latitude = 0;
    Projection projection = map.getProjection();
    android.graphics.Point ptPixels = null;
    for (j = 0; j < _pointsGeo.size(); j++) {
        ptGeo = _pointsGeo.get(j);
        longitude = ptGeo.longitude;
        latitude = ptGeo.longitude;
        ptPixels = projection.toScreenLocation(ptGeo);
        _points.add(new Point(ptPixels.x, ptPixels.y));
    }
}
 
Example 3
Source File: MapUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Build a lat lng bounding box using the click location, map view, map, and screen percentage tolerance.
 * The bounding box can be used to query for features that were clicked
 *
 * @param latLng                click location
 * @param view                  map view
 * @param map                   map
 * @param screenClickPercentage screen click percentage between 0.0 and 1.0 for how close a feature
 *                              on the screen must be to be included in a click query
 * @return lat lng bounding box
 */
public static LatLngBoundingBox buildClickLatLngBoundingBox(LatLng latLng, View view, GoogleMap map, float screenClickPercentage) {

    // Get the screen width and height a click occurs from a feature
    int width = (int) Math.round(view.getWidth() * screenClickPercentage);
    int height = (int) Math.round(view.getHeight() * screenClickPercentage);

    // Get the screen click location
    Projection projection = map.getProjection();
    android.graphics.Point clickLocation = projection.toScreenLocation(latLng);

    // Get the screen click locations in each width or height direction
    android.graphics.Point left = new android.graphics.Point(clickLocation);
    android.graphics.Point up = new android.graphics.Point(clickLocation);
    android.graphics.Point right = new android.graphics.Point(clickLocation);
    android.graphics.Point down = new android.graphics.Point(clickLocation);
    left.offset(-width, 0);
    up.offset(0, -height);
    right.offset(width, 0);
    down.offset(0, height);

    // Get the coordinates of the bounding box points
    LatLng leftCoordinate = projection.fromScreenLocation(left);
    LatLng upCoordinate = projection.fromScreenLocation(up);
    LatLng rightCoordinate = projection.fromScreenLocation(right);
    LatLng downCoordinate = projection.fromScreenLocation(down);

    LatLngBoundingBox latLngBoundingBox = new LatLngBoundingBox(leftCoordinate, upCoordinate, rightCoordinate, downCoordinate);

    return latLngBoundingBox;
}
 
Example 4
Source File: RichPolygon.java    From richmaps with Apache License 2.0 5 votes vote down vote up
protected void drawFill(final Bitmap bitmap, final Projection projection,
                        final List<RichPoint> points2Draw,
                        final int paddingLeft, final int paddingTop,
                        final int paddingRight, final int paddingBottom) {
    Canvas canvas = new Canvas(bitmap);
    Path linePath = new Path();
    boolean firstPoint = true;
    for (RichPoint point : points2Draw) {
        LatLng position = point.getPosition();
        if (position != null) {
            Point bmpPoint = projection.toScreenLocation(position);
            int bmpPointX = bmpPoint.x;
            int bmpPointY = bmpPoint.y + paddingBottom / 2 - paddingTop / 2;

            if (firstPoint) {
                linePath.moveTo(bmpPointX, bmpPointY);
                firstPoint = false;
            } else {
                linePath.lineTo(bmpPointX, bmpPointY);
            }
        }
    }

    Paint paint = getDefaultFillPaint();
    if (fillShader != null) {
        paint.setShader(fillShader);
    }
    canvas.drawPath(linePath, paint);
}
 
Example 5
Source File: RichPolyline.java    From richmaps with Apache License 2.0 5 votes vote down vote up
private void drawSegment(final Canvas canvas, final Paint paint,
                         final Projection projection,
                         final RichPoint from, final RichPoint to,
                         final int paddingLeft, final int paddingTop,
                         final int paddingRight, final int paddingBottom) {
    Point toScreenPoint = projection.toScreenLocation(to.getPosition());
    Point fromScreenPoint = projection.toScreenLocation(from.getPosition());

    int fromX = fromScreenPoint.x + paddingRight / 2 - paddingLeft / 2;
    int fromY = fromScreenPoint.y + paddingBottom / 2 - paddingTop / 2;
    int toX = toScreenPoint.x + paddingRight / 2 - paddingLeft / 2;
    int toY = toScreenPoint.y + paddingBottom / 2 - paddingTop / 2;

    if (linearGradient) {
        int[] colors = new int[]{from.getColor(), to.getColor()};
        paint.setShader(new LinearGradient(fromX, fromY, toX, toY,
                colors, null, Shader.TileMode.CLAMP));
    } else {
        paint.setColor(from.getColor());
    }

    if (strokeShader != null) {
        paint.setShader(strokeShader);
    }

    canvas.drawLine(fromX, fromY, toX, toY, paint);
}
 
Example 6
Source File: LocationActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void updatePositions() {
    if (googleMap == null) {
        return;
    }
    Projection projection = googleMap.getProjection();
    for (HashMap.Entry<Marker, View> entry : views.entrySet()) {
        Marker marker = entry.getKey();
        View view = entry.getValue();
        Point point = projection.toScreenLocation(marker.getPosition());
        view.setTranslationX(point.x - view.getMeasuredWidth() / 2);
        view.setTranslationY(point.y - view.getMeasuredHeight() + AndroidUtilities.dp(22));
    }
}
 
Example 7
Source File: ChatAttachAlertLocationLayout.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void updatePositions() {
    if (googleMap == null) {
        return;
    }
    Projection projection = googleMap.getProjection();
    for (HashMap.Entry<Marker, View> entry : views.entrySet()) {
        Marker marker = entry.getKey();
        View view = entry.getValue();
        Point point = projection.toScreenLocation(marker.getPosition());
        view.setTranslationX(point.x - view.getMeasuredWidth() / 2);
        view.setTranslationY(point.y - view.getMeasuredHeight() + AndroidUtilities.dp(22));
    }
}
 
Example 8
Source File: BasePoint.java    From clusterkraf with Apache License 2.0 4 votes vote down vote up
void buildScreenPosition(Projection projection) {
	if (projection != null && mapPosition != null) {
		screenPosition = projection.toScreenLocation(mapPosition);
	}
}