Java 类com.google.android.gms.maps.Projection 实例源码

项目:PhoneChat    文件:GoogleMaps.java   
/**
 * Intersection for non-geodesic line
 * @ref http://movingahead.seesaa.net/article/299962216.html
 * @ref http://www.softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line-Plane
 *
 * @param points
 * @param point
 * @return
 */
private boolean isPointOnTheLine(List<LatLng> points, LatLng point) {
  double Sx, Sy;
  Projection projection = map.getProjection();
  Point p0, p1, touchPoint;
  touchPoint = projection.toScreenLocation(point);

  p0 = projection.toScreenLocation(points.get(0));
  for (int i = 1; i < points.size(); i++) {
    p1 = projection.toScreenLocation(points.get(i));
    Sx = ((double)touchPoint.x - (double)p0.x) / ((double)p1.x - (double)p0.x);
    Sy = ((double)touchPoint.y - (double)p0.y) / ((double)p1.y - (double)p0.y);
    if (Math.abs(Sx - Sy) < 0.05 && Sx < 1 && Sx > 0) {
      return true;
    }
    p0 = p1;
  }
  return false;
}
项目:PGMacTips    文件:ScaleBar.java   
private void drawScaleBarPicture(Canvas canvas) {
    // We want the scale bar to be as long as the closest round-number miles/kilometers
    // to 1-inch at the latitude at the current center of the screen.

    Projection projection = mMap.getProjection();

    if (projection == null) {
        return;
    }

    final Paint barPaint = new Paint();
    barPaint.setColor(Color.BLACK);
    barPaint.setAntiAlias(true);
    barPaint.setStrokeWidth(mLineWidth);

    final Paint textPaint = new Paint();
    textPaint.setColor(Color.BLACK);
    textPaint.setAntiAlias(true);
    textPaint.setTextSize(dmu.getScalablePixelTextSize(TEXT_SIZE_BASE));

    drawXMetric(canvas, textPaint, barPaint);

    drawYMetric(canvas, textPaint, barPaint);
}
项目:richmaps    文件:RichPolygon.java   
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);
}
项目:xamoom-pingeborg-android    文件:MapFragment.java   
/**
 * Zooms the map to a marker, so that it will be above
 * the MapAdditionFragment.
 *
 * @param marker A Marker from a GoogleMap.
 */
public void zoomMapToMarker(Marker marker) {
    //move camera to display marker above the mapAddtionFragment
    Projection projection = mGoogleMap.getProjection();

    LatLng markerLatLng = new LatLng(marker.getPosition().latitude,
            marker.getPosition().longitude);
    Point markerScreenPosition = projection.toScreenLocation(markerLatLng);
    Point pointHalfScreenAbove = new Point(markerScreenPosition.x,
            markerScreenPosition.y + (this.getResources().getDisplayMetrics().heightPixels / 5));

    LatLng aboveMarkerLatLng = projection
            .fromScreenLocation(pointHalfScreenAbove);

    marker.showInfoWindow();
    CameraUpdate center = CameraUpdateFactory.newLatLng(aboveMarkerLatLng);
    mGoogleMap.animateCamera(center);
}
项目:AirMapView    文件:NativeGoogleMapFragment.java   
@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());
}
项目:neo4art    文件:GoogleMaps.java   
/**
 * Intersection for non-geodesic line
 * @ref http://movingahead.seesaa.net/article/299962216.html
 * @ref http://www.softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line-Plane
 * 
 * @param points
 * @param point
 * @return
 */
private boolean isPointOnTheLine(List<LatLng> points, LatLng point) {
  double Sx, Sy;
  Projection projection = map.getProjection();
  Point p0, p1, touchPoint;
  touchPoint = projection.toScreenLocation(point);

  p0 = projection.toScreenLocation(points.get(0));
  for (int i = 1; i < points.size(); i++) {
    p1 = projection.toScreenLocation(points.get(i));
    Sx = ((double)touchPoint.x - (double)p0.x) / ((double)p1.x - (double)p0.x);
    Sy = ((double)touchPoint.y - (double)p0.y) / ((double)p1.y - (double)p0.y);
    if (Math.abs(Sx - Sy) < 0.05 && Sx < 1 && Sx > 0) {
      return true;
    }
    p0 = p1;
  }
  return false;
}
项目:neo4art    文件:GoogleMaps.java   
/**
 * Intersection for non-geodesic line
 * @ref http://movingahead.seesaa.net/article/299962216.html
 * @ref http://www.softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line-Plane
 * 
 * @param points
 * @param point
 * @return
 */
private boolean isPointOnTheLine(List<LatLng> points, LatLng point) {
  double Sx, Sy;
  Projection projection = map.getProjection();
  Point p0, p1, touchPoint;
  touchPoint = projection.toScreenLocation(point);

  p0 = projection.toScreenLocation(points.get(0));
  for (int i = 1; i < points.size(); i++) {
    p1 = projection.toScreenLocation(points.get(i));
    Sx = ((double)touchPoint.x - (double)p0.x) / ((double)p1.x - (double)p0.x);
    Sy = ((double)touchPoint.y - (double)p0.y) / ((double)p1.y - (double)p0.y);
    if (Math.abs(Sx - Sy) < 0.05 && Sx < 1 && Sx > 0) {
      return true;
    }
    p0 = p1;
  }
  return false;
}
项目:neo4art    文件:GoogleMaps.java   
/**
 * Intersection for non-geodesic line
 * @ref http://movingahead.seesaa.net/article/299962216.html
 * @ref http://www.softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line-Plane
 * 
 * @param points
 * @param point
 * @return
 */
private boolean isPointOnTheLine(List<LatLng> points, LatLng point) {
  double Sx, Sy;
  Projection projection = map.getProjection();
  Point p0, p1, touchPoint;
  touchPoint = projection.toScreenLocation(point);

  p0 = projection.toScreenLocation(points.get(0));
  for (int i = 1; i < points.size(); i++) {
    p1 = projection.toScreenLocation(points.get(i));
    Sx = ((double)touchPoint.x - (double)p0.x) / ((double)p1.x - (double)p0.x);
    Sy = ((double)touchPoint.y - (double)p0.y) / ((double)p1.y - (double)p0.y);
    if (Math.abs(Sx - Sy) < 0.05 && Sx < 1 && Sx > 0) {
      return true;
    }
    p0 = p1;
  }
  return false;
}
项目:beacon-frontend    文件:ConstrainedCameraMap.java   
protected void putLatLngAtScreenCoords(LatLng loc, Point target) {
    LatLng curTarget = mMap.getCameraPosition().target;
    Projection projection = mMap.getProjection();
    double selectLat = projection.fromScreenLocation(target).latitude;

    double targetLongitude = loc.longitude;
    double targetLatitude = loc.latitude + (curTarget.latitude - selectLat);

    LatLng latLngTarget = new LatLng(targetLatitude, targetLongitude);
    float zoom = mMap.getCameraPosition().zoom;

    CameraPosition movement = new CameraPosition.Builder()
            .target(latLngTarget)
            .zoom(zoom)
            .tilt(zoomToTilt(zoom))
            .build();

    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(movement), 500, null);
}
项目:android_programmering_2014    文件:MainActivity.java   
public void animateMarker(final Marker marker, final LatLng toPosition) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);
    final long duration = 500;

    final Interpolator interpolator = new LinearInterpolator();

    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));

            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });
}
项目:mil-sym-android    文件:MyView.java   
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));
    }
}
项目:google-maps-blog-android-sample-code    文件:ClustersAreListsActivity.java   
private void showInfoWindow(Cluster cluster) {
    Marker m = cluster.get(0);
    // Save the current camera so we can restore it later
    previousCameraPosition = map.getCameraPosition();

    // Get the screen-space position of the Cluster
    int yoffset = markerSize / 2;
Projection proj = map.getProjection();
      Point p = proj.toScreenLocation(m.getPosition());
      int markerX = p.x;
      int markerY = p.y - yoffset;

// Get the position where we'll ultimately show the marker & spotlight
final Point newMarkerPos = getZoneCenter(m);

// Animate the spotlight from the current marker position to its final position
showSpotlight(markerX, markerY, newMarkerPos.x, newMarkerPos.y);

// Position the selected marker in the top, right, bottom, or left zone
final CameraUpdate camUpdate = calculateCameraChange(newMarkerPos.x, newMarkerPos.y, 
        markerX, markerY);
map.animateCamera(camUpdate, 400, null);
// Show the popup list next to the marker
showInfo(newMarkerPos.x + markerSize/2, newMarkerPos.y + yoffset, cluster);
  }
项目:xposed-gps    文件:MainActivity.java   
public void onCameraChange(CameraPosition position) {
    LatLng pos = mMarker.getPosition();
    final Projection proj = mMap.getProjection();
    final VisibleRegion vr = proj.getVisibleRegion();
    final LatLng farLeft = vr.farLeft;
    final LatLng farRight = vr.farRight;
    final LatLng nearLeft = vr.nearLeft;
    final LatLng nearRight = vr.nearRight;

    double screenLat = Math.abs(farLeft.latitude - nearRight.latitude) / 2.0;
    double screenLng = Math.abs(farLeft.longitude - nearRight.longitude) / 2.0;

    double latDiff = Math.abs(mInit.latitude - position.target.latitude);
    double lngDiff = Math.abs(mInit.longitude - position.target.longitude);

    if (latDiff > screenLat || lngDiff > screenLng) {
        double cLat = mMap.getCameraPosition().target.latitude;
        double cLng = mMap.getCameraPosition().target.longitude;
        mInit = new LatLng(cLat, cLng);
        mMarker.position(mInit);
        mMap.clear();
        mMap.addMarker(mMarker);
    }

}
项目:clusterkraf    文件:ClusterTransitions.java   
void add(ClusterPoint currentClusterPoint) {
    Projection projection = projectionRef != null ? projectionRef.get() : null;
    if (currentClusterPoint != null && projection != null) {
        boolean animated = false;
        if (previousClusterPoints != null) {
            for (ClusterPoint previousClusterPoint : previousClusterPoints) {
                for (InputPoint previousInputPoint : previousClusterPoint.getPointsInCluster()) {
                    if (currentClusterPoint.containsInputPoint(previousInputPoint)) {
                        AnimatedTransition transition = getTransition(previousInputPoint);
                        if (transition != null) {
                            transition.addOriginClusterRelevantInputPoint(previousInputPoint);
                        } else {
                            transition = new AnimatedTransition(projection, previousClusterPoint, previousInputPoint, currentClusterPoint);
                            animatedTransitions.add(transition);
                            animated = true;
                        }
                    }
                }
            }
        }
        if (animated == false) {
            stationaryTransitions.add(currentClusterPoint);
        }
    }
}
项目:clusterkraf    文件:ClustersBuilder.java   
ArrayList<ClusterPoint> build() {
    Projection projection = getProjection();
    ArrayList<ClusterPoint> clusteredPoints = null;
    if (projection != null) {
        clusteredPoints = new ArrayList<ClusterPoint>(relevantInputPointsList.size());
        for (InputPoint point : relevantInputPointsList) {
            boolean addedToExistingCluster = false;
            for (ClusterPoint clusterPoint : clusteredPoints) {
                if (clusterPoint.getPixelDistanceFrom(point) <= options.getPixelDistanceToJoinCluster()) {
                    clusterPoint.add(point);
                    addedToExistingCluster = true;
                    break;
                }
            }
            if (addedToExistingCluster == false) {
                clusteredPoints.add(new ClusterPoint(point, projection, false));
            }
        }
    }
    return clusteredPoints;
}
项目:Farmacias    文件:MapTabFragment.java   
@Override
public void onMapClick(LatLng latLng) {
    Projection projection = mMap.getProjection();
    Point point = projection.toScreenLocation(latLng);

    Rect rect = new Rect();
    bottomSheet.getGlobalVisibleRect(rect);
    if (!rect.contains(point.x, point.y)) {
        Utils.logD(LOG_TAG, "outside bottom sheet");
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    }
}
项目:FiveMinsMore    文件:ScaleBar.java   
private void drawXMetric(Canvas canvas, Paint textPaint, Paint barPaint) {
    Projection projection = mMap.getProjection();

    if (projection != null) {
        LatLng p1 = projection.fromScreenLocation(new Point((int) ((getWidth() / 2) - (mXdpi / 2)), getHeight() / 2));
        LatLng p2 = projection.fromScreenLocation(new Point((int) ((getWidth() / 2) + (mXdpi / 2)), getHeight() / 2));

        Location locationP1 = new Location("ScaleBar location p1");
        Location locationP2 = new Location("ScaleBar location p2");

        locationP1.setLatitude(p1.latitude);
        locationP2.setLatitude(p2.latitude);
        locationP1.setLongitude(p1.longitude);
        locationP2.setLongitude(p2.longitude);

        float xMetersPerInch = locationP1.distanceTo(locationP2);

        if (mIsLatitudeBar) {
            String xMsg = scaleBarLengthText(xMetersPerInch);
            Rect xTextRect = new Rect();
            textPaint.getTextBounds(xMsg, 0, xMsg.length(), xTextRect);

            int textSpacing = (int) (xTextRect.height() / 5.0);

            canvas.drawRect(mXOffset, mYOffset, mXOffset + mXdpi, mYOffset + mLineWidth, barPaint);
            canvas.drawRect(mXOffset + mXdpi, mYOffset, mXOffset + mXdpi + mLineWidth, mYOffset +
                    xTextRect.height() + mLineWidth + textSpacing, barPaint);

            if (!mIsLongitudeBar) {
                canvas.drawRect(mXOffset, mYOffset, mXOffset + mLineWidth, mYOffset +
                        xTextRect.height() + mLineWidth + textSpacing, barPaint);
            }
            canvas.drawText(xMsg, (mXOffset + mXdpi / 2 - xTextRect.width() / 2),
                    (mYOffset + xTextRect.height() + mLineWidth + textSpacing), textPaint);
        }
    }
}
项目:treehugger    文件:DBhandler.java   
public static List<Tree> getRegionTreeList(Context context, Projection projectionRigion) {

        if (dbstatic == null) {
            TreeDBHelper dbHelper = new TreeDBHelper(context);
            dbstatic = dbHelper.getReadableDatabase();
        }

        String[] projection = new String[]{TreeDBContract.TreeEntry.COLUMN_NAME_TRAE_ART,
                TreeDBContract.TreeEntry.COLUMN_NAME_DANSK_NAVN,
                COLUMN_NAME_COORDINATE_LAT,
                TreeDBContract.TreeEntry.COLUMN_NAME_COORDINATE_LON};

        LatLngBounds bounds = projectionRigion.getVisibleRegion().latLngBounds;

        String selection = COLUMN_NAME_COORDINATE_LAT +
                " Between " + bounds.southwest.latitude +
                " And " + bounds.northeast.latitude +
                " And " + COLUMN_NAME_COORDINATE_LON +
                " Between " + bounds.southwest.longitude +
                " And " + bounds.northeast.longitude +
                " LIMIT 2000";

        Cursor cursor = dbstatic.query(TreeDBContract.TreeEntry.TABLE_NAME, projection, selection, null, null, null, null);
        List<Tree> trees = new ArrayList<>(cursor.getCount());
        while (cursor.moveToNext()) {
            Tree tree = new Tree(cursor.getString(cursor.getColumnIndex(TreeDBContract.TreeEntry.COLUMN_NAME_TRAE_ART)),
                    cursor.getString(cursor.getColumnIndex(TreeDBContract.TreeEntry.COLUMN_NAME_DANSK_NAVN)),
                    cursor.getDouble(cursor.getColumnIndex(COLUMN_NAME_COORDINATE_LAT)),
                    cursor.getDouble(cursor.getColumnIndex(TreeDBContract.TreeEntry.COLUMN_NAME_COORDINATE_LON)));
            trees.add(tree);
        }
        cursor.close();

        return trees;
    }
项目:geopackage-android-map    文件:MapUtils.java   
/**
 * 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;
}
项目:KortidTol    文件:QuickHull.java   
public ArrayList<Point> convertToPoint(List<LatLng> coords, Projection projection){
  ArrayList<Point> points = new ArrayList<Point>();

  for(LatLng coord : coords){
    points.add(projection.toScreenLocation(coord));
  }

  return points;
}
项目:KortidTol    文件:QuickHull.java   
public ArrayList<LatLng> convertToLatLng(List<Point> points, Projection projection){
  ArrayList<LatLng> coords = new ArrayList<LatLng>();

  for(Point point : points){
    coords.add(projection.fromScreenLocation(point));
  }

  return coords;
}
项目:KortidTol    文件:ConcaveHull.java   
private Coordinate[] convertToCoords(List<LatLng> latLngs, Projection projection){
  int count = latLngs.size();
  Coordinate[] coords = new Coordinate[count];
  int index = 0;
  for(LatLng latLng : latLngs){
    Point p = projection.toScreenLocation(latLng);
    coords[index] = new Coordinate(p.x, p.y);
      index++;
  }

  return coords;
}
项目:PhoneChat    文件:GoogleMaps.java   
/**
 * Intersects using the Winding Number Algorithm
 * @ref http://www.nttpc.co.jp/company/r_and_d/technology/number_algorithm.html
 * @param path
 * @param point
 * @return
 */
private boolean isPolygonContains(List<LatLng> path, LatLng point) {
  int wn = 0;
  Projection projection = map.getProjection();
  VisibleRegion visibleRegion = projection.getVisibleRegion();
  LatLngBounds bounds = visibleRegion.latLngBounds;
  Point sw = projection.toScreenLocation(bounds.southwest);

  Point touchPoint = projection.toScreenLocation(point);
  touchPoint.y = sw.y - touchPoint.y;
  double vt;

  for (int i = 0; i < path.size() - 1; i++) {
    Point a = projection.toScreenLocation(path.get(i));
    a.y = sw.y - a.y;
    Point b = projection.toScreenLocation(path.get(i + 1));
    b.y = sw.y - b.y;

    if ((a.y <= touchPoint.y) && (b.y > touchPoint.y)) {
      vt = ((double)touchPoint.y - (double)a.y) / ((double)b.y - (double)a.y);
      if (touchPoint.x < ((double)a.x + (vt * ((double)b.x - (double)a.x)))) {
        wn++;
      }
    } else if ((a.y > touchPoint.y) && (b.y <= touchPoint.y)) {
      vt = ((double)touchPoint.y - (double)a.y) / ((double)b.y - (double)a.y);
      if (touchPoint.x < ((double)a.x + (vt * ((double)b.x - (double)a.x)))) {
        wn--;
      }
    }
  }

  return (wn != 0);
}
项目:PhoneChat    文件:PluginMarker.java   
private void setDropAnimation_(final Marker marker, final PluginAsyncInterface callback) {
  final Handler handler = new Handler();
  final long startTime = SystemClock.uptimeMillis();
  final long duration = 100;

  final Projection proj = this.map.getProjection();
  final LatLng markerLatLng = marker.getPosition();
  final Point markerPoint = proj.toScreenLocation(markerLatLng);
  final Point startPoint = new Point(markerPoint.x, 0);

  final Interpolator interpolator = new LinearInterpolator();

  handler.post(new Runnable() {
    @Override
    public void run() {
      LatLng startLatLng = proj.fromScreenLocation(startPoint);
      long elapsed = SystemClock.uptimeMillis() - startTime;
      float t = interpolator.getInterpolation((float) elapsed / duration);
      double lng = t * markerLatLng.longitude + (1 - t) * startLatLng.longitude;
      double lat = t * markerLatLng.latitude + (1 - t) * startLatLng.latitude;
      marker.setPosition(new LatLng(lat, lng));
      if (t < 1.0) {
        // Post again 16ms later.
        handler.postDelayed(this, 16);
      } else {
        marker.setPosition(markerLatLng);
        callback.onPostExecute(marker);
      }
    }
  });
}
项目:PhoneChat    文件:PluginMarker.java   
/**
 * Bounce animation
 * http://android-er.blogspot.com/2013/01/implement-bouncing-marker-for-google.html
 */
private void setBounceAnimation_(final Marker marker, final PluginAsyncInterface callback) {
  final Handler handler = new Handler();
  final long startTime = SystemClock.uptimeMillis();
  final long duration = 2000;

  final Projection proj = this.map.getProjection();
  final LatLng markerLatLng = marker.getPosition();
  final Point startPoint = proj.toScreenLocation(markerLatLng);
  startPoint.offset(0, -200);

  final Interpolator interpolator = new BounceInterpolator();

  handler.post(new Runnable() {
    @Override
    public void run() {
      LatLng startLatLng = proj.fromScreenLocation(startPoint);
      long elapsed = SystemClock.uptimeMillis() - startTime;
      float t = interpolator.getInterpolation((float) elapsed / duration);
      double lng = t * markerLatLng.longitude + (1 - t) * startLatLng.longitude;
      double lat = t * markerLatLng.latitude + (1 - t) * startLatLng.latitude;
      marker.setPosition(new LatLng(lat, lng));

      if (t < 1.0) {
        // Post again 16ms later.
        handler.postDelayed(this, 16);
      } else {
        marker.setPosition(markerLatLng);
        callback.onPostExecute(marker);
      }
    }
  });
}
项目:Tower-develop    文件:GoogleMapFragment.java   
@Override
public List<LatLong> projectPathIntoMap(List<LatLong> path) {
    List<LatLong> coords = new ArrayList<LatLong>();
    Projection projection = getMap().getProjection();

    for (LatLong point : path) {
        LatLng coord = projection.fromScreenLocation(new Point((int) point
                .getLatitude(), (int) point.getLongitude()));
        coords.add(MapUtils.latLngToCoord(coord));
    }

    return coords;
}
项目:trail-android    文件:RouteOverlayView.java   
public void loadPath(LatLng fromLatlng, LatLng toLatlng, GoogleMap map) {
  isArc = true;
  Projection projection = mProjectionHelper.getProjection();
  this.zoomAnchor = mProjectionHelper.getCameraPosition().zoom;
  mProjectionHelper.setCenterlatLng(projection
      .fromScreenLocation(new Point(getWidth()/2, getHeight()/2)));
  onCameraMove(map);

  if (fromLatlng == null || toLatlng == null) return;

  mRoutePath.rewind();
  mArcLoadingPath.rewind();

  pickUpPoint = projection.toScreenLocation(fromLatlng);
  dropPoint = projection.toScreenLocation(toLatlng);

  mArcLoadingPath = Util.createCurvedPath(pickUpPoint.x, pickUpPoint.y, dropPoint.x, dropPoint.y, 180);

  PathMeasure pathMeasure = new PathMeasure(mArcLoadingPath, false);
  mAnimationArcHelper.length = pathMeasure.getLength();
  mAnimationArcHelper.dashValue = new float[] { mAnimationArcHelper.length, mAnimationArcHelper.length };

  new Handler(Looper.getMainLooper()).post(new Runnable() {
    @Override
    public void run() {
      mAnimationArcHelper.init();
      mAnimationArcHelper.play();
    }
  });

  isPathSetup = true;
}
项目:calchoochoo    文件:MapUtils.java   
static public void animateMarker(final Marker marker, final LatLng toPosition, GoogleMap googleMap) {
  final Handler handler = new Handler();
  final long start = SystemClock.uptimeMillis();
  Projection projection = googleMap.getProjection();
  Point startPoint = projection.toScreenLocation(marker.getPosition());
  final LatLng startLatLng = projection.fromScreenLocation(startPoint);
  final long duration = 500;

  final Interpolator interpolator = new LinearInterpolator();

  handler.post(new Runnable() {
    @Override
    public void run() {
      long elapsed = SystemClock.uptimeMillis() - start;
      float t = interpolator.getInterpolation((float) elapsed
          / duration);
      double lng = t * toPosition.longitude + (1 - t)
          * startLatLng.longitude;
      double lat = t * toPosition.latitude + (1 - t)
          * startLatLng.latitude;
      marker.setPosition(new LatLng(lat, lng));

      if (t < 1.0) {
        // Post again 16ms later.
        handler.postDelayed(this, 16);
      } else {
        marker.setVisible(true);
      }
    }
  });
}
项目:richmaps    文件:RichPolygon.java   
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);
}
项目:richmaps    文件:RichLayer.java   
public void refresh() {
    CameraPosition cameraPosition = map.getCameraPosition();
    if (cameraPosition.zoom >= MINIMUM_ZOOM_LEVEL) {
        Projection projection = map.getProjection();

        prepareBitmap();
        draw(bitmap, projection);

        float mapWidth = (float) SphericalUtil.computeDistanceBetween(
                projection.getVisibleRegion().nearLeft,
                projection.getVisibleRegion().nearRight);

        if (overlay == null) {
            GroundOverlayOptions background = new GroundOverlayOptions()
                    .image(BitmapDescriptorFactory.fromBitmap(bitmap))
                    .position(cameraPosition.target, mapWidth)
                    .bearing(cameraPosition.bearing)
                    .zIndex(zIndex);
            overlay = map.addGroundOverlay(background);
        } else {
            overlay.setImage(BitmapDescriptorFactory.fromBitmap(bitmap));
            overlay.setPosition(cameraPosition.target);
            overlay.setDimensions(mapWidth);
            overlay.setBearing(cameraPosition.bearing);
        }
    } else {
        if (overlay != null) {
            overlay.remove();
            overlay = null;
        }
    }
}
项目:richmaps    文件:RichLayer.java   
private Bitmap draw(final Bitmap bitmap, final Projection projection) {
    Set<Integer> zIndices = shapes.keySet();
    for (Integer zIndex : zIndices) {
        draw(bitmap, projection, shapes.get(zIndex));
    }

    return bitmap;
}
项目:richmaps    文件:RichLayer.java   
private Bitmap draw(final Bitmap bitmap, final Projection projection,
                    final List<RichShape> shapes) {
    for (RichShape shape : shapes) {
        shape.draw(bitmap, projection, paddingLeft, paddingTop, paddingRight, paddingBottom);
    }
    return bitmap;
}
项目:richmaps    文件:RichShape.java   
public void draw(final Bitmap bitmap, final Projection projection,
                 final int paddingLeft, final int paddingTop,
                 final int paddingRight, final int paddingBottom) {
    if (bitmap == null || projection == null) {
        throw new IllegalStateException("Bitmap and Projection cannot be null");
    }

    if (boundsIntersects(projection.getVisibleRegion().latLngBounds)) {
        doDraw(bitmap, projection, paddingLeft, paddingTop, paddingRight, paddingBottom);
    }
}
项目:richmaps    文件:RichPolyline.java   
protected void drawStroke(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);
    Paint paint = getDefaultStrokePaint();

    RichPoint firstPoint = null;
    boolean first = true;
    RichPoint lastPoint = null;
    for (RichPoint point : points2Draw) {
        paint = getDefaultStrokePaint();
        LatLng position = point.getPosition();
        if (position != null) {
            if (first) {
                firstPoint = point;
                first = false;
            }

            if (point.getColor() == null) {
                point.color(strokeColor);
            }

            if (lastPoint != null) {
                drawSegment(canvas, paint, projection, lastPoint, point,
                        paddingLeft, paddingTop, paddingRight, paddingBottom);
            }
            lastPoint = point;
        }
    }

    if (closed && firstPoint != null && lastPoint != null) {
        drawSegment(canvas, paint, projection, lastPoint, firstPoint,
                paddingLeft, paddingTop, paddingRight, paddingBottom);
    }
}
项目:richmaps    文件:RichPolyline.java   
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);
}
项目:geohashdroid    文件:ExpeditionMode.java   
private void checkInfoBoxFading() {
    if(mCurrentInfo == null) return;

    boolean fade;
    mInfoBox.getLocationRect(mInfoBoxDimens);

    // First, check the final destination marker.  The pin on the flag is
    // where the point is, so we would want to check against the entire
    // height of it to see if it crashes into the InfoBox.
    Projection proj = mMap.getProjection();
    Point p = proj.toScreenLocation(mCurrentInfo.getFinalDestinationLatLng());
    mMarkerDimens.set(p.x - (mMarkerWidth / 2),
            p.y - mMarkerHeight,
            p.x + (mMarkerWidth / 2),
            p.y);
    fade = Rect.intersects(mMarkerDimens, mInfoBoxDimens);

    if(!fade) {
        // Continue with current location checking.  We'll use the same
        // bounds as the final destination marker, just for convenience.
        Location loc = getLastKnownLocation();
        if(LocationUtil.isLocationNewEnough(loc)) {
            p = proj.toScreenLocation(new LatLng(loc.getLatitude(), loc.getLongitude()));
            // Except, remember, the current location marker is pinned at
            // the CENTER of the image.  Tricky!
            mMarkerDimens.set(p.x - (mMarkerWidth / 2),
                    p.y - (mMarkerHeight / 2),
                    p.x + (mMarkerWidth / 2),
                    p.y + (mMarkerHeight / 2));

            fade = Rect.intersects(mMarkerDimens, mInfoBoxDimens);
        }
    }

    mInfoBox.fadeOutInfoBox(fade);
}
项目:fme-apps-android    文件:SendLocationAndUpdateMapTask.java   
/**
 * Make the marker fly towards toPosition on map. Sets the position of the
 * MarkerOption point to toPosition.
 * 
 * @param marker
 * @param toPosition
 * @param point
 * @param deltaHeight
 */
public void animateMarker(final Marker marker, final LatLng toPosition,
      final MarkerOptions point, final String[] results, int deltaHeight) {
   final Handler handler = new Handler();
   final long start = SystemClock.uptimeMillis();
   Projection proj = mMap.getProjection();
   Point startPoint = proj.toScreenLocation(marker.getPosition());

   final LatLng startLatLng = proj.fromScreenLocation(startPoint);
   final long duration = 500 + (deltaHeight > 0 ? deltaHeight : 0);
   final Interpolator interpolator = new LinearInterpolator();
   handler.post(new Runnable() {
      public void run() {
         long elapsed = SystemClock.uptimeMillis() - start;
         float t = interpolator.getInterpolation((float) elapsed / duration);
         double lng = t * toPosition.longitude + (1 - t)
               * startLatLng.longitude;
         double lat = t * toPosition.latitude + (1 - t)
               * startLatLng.latitude;
         marker.setPosition(new LatLng(lat, lng));
         if (t < 1.0) {
            // Post again 16ms later.
            handler.postDelayed(this, 16);
         } else {
            point.position(toPosition);
            marker.setPosition(toPosition);
            marker.remove();
            insertIntoDatabase(results);
         }
      }
   });
   if (PreferenceManager.getDefaultSharedPreferences(mainActivity)
         .getBoolean("automovecamera", false))
      mMap.animateCamera(CameraUpdateFactory.newLatLng(toPosition));
}
项目:fme-apps-android    文件:SendLocationAndUpdateMapTask.java   
/**
 * Make the marker fly towards toPosition on map. Sets the position of the
 * MarkerOption point to toPosition.
 * 
 * @param marker
 * @param toPosition
 * @param point
 */
public void animateMarker(final Marker marker, final LatLng toPosition,
        final MarkerOptions point) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);
    final long duration = 500;
    final Interpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed
                    / duration);
            double lng = t * toPosition.longitude + (1 - t)
                    * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t)
                    * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));
            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            } else {
                point.position(toPosition);
                marker.setPosition(toPosition);
                marker.setVisible(true);
                mainActivity.addMarkerToList(point);
            }
        }
    });
    map.animateCamera(CameraUpdateFactory.newLatLng(toPosition));
}
项目:saarang-iosched    文件:MapFragment.java   
private void centerMap(LatLng position) {
    // calculate the new center of the map, taking into account optional
    // padding
    Projection proj = mMap.getProjection();
    Point p = proj.toScreenLocation(position);

    // apply padding
    p.x = (int) (p.x - Math.round(mWidth * 0.5)) + mShiftRight;
    p.y = (int) (p.y - Math.round(mHeight * 0.5)) + mShiftTop;

    mMap.animateCamera(CameraUpdateFactory.scrollBy(p.x, p.y));
}
项目:AppDevFestSudeste2015    文件:MapFragment.java   
private void centerMap(LatLng position) {
    // calculate the new center of the map, taking into account optional
    // padding
    Projection proj = mMap.getProjection();
    Point p = proj.toScreenLocation(position);

    // apply padding
    p.x = (int) (p.x - Math.round(mWidth * 0.5)) + mShiftRight;
    p.y = (int) (p.y - Math.round(mHeight * 0.5)) + mShiftTop;

    mMap.animateCamera(CameraUpdateFactory.scrollBy(p.x, p.y));
}