本文整理匯總了Java中com.google.android.gms.maps.Projection.fromScreenLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java Projection.fromScreenLocation方法的具體用法?Java Projection.fromScreenLocation怎麽用?Java Projection.fromScreenLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.android.gms.maps.Projection
的用法示例。
在下文中一共展示了Projection.fromScreenLocation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: zoomMapToMarker
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
/**
* 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);
}
示例2: putLatLngAtScreenCoords
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
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);
}
示例3: animateMarker
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
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);
}
}
});
}
示例4: drawXMetric
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
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);
}
}
}
示例5: buildClickLatLngBoundingBox
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
/**
* 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;
}
示例6: projectPathIntoMap
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
@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;
}
示例7: animateMarker
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
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);
}
}
});
}
示例8: animateMarker
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
/**
* 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));
}
示例9: animateMarker
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
/**
* 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));
}
示例10: projectPathIntoMap
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
@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(DroneHelper.LatLngToCoord(coord));
}
return coords;
}
示例11: calculateDistanceBetweenMarkers
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
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;
}
示例12: updateMyLocationMarkerAnimated
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
void updateMyLocationMarkerAnimated(@NonNull final LatLng target) {
if (gMap == null) return;
final long duration = 250;
handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = gMap.getProjection();
Point startPoint = proj.toScreenLocation(myLocationMarker.getPosition());
final LatLng startLatLng = proj.fromScreenLocation(startPoint);
if (startPoint == null || startLatLng == null) {
Log.w(TAG,
new RuntimeException(String.format(
">startPoint == null? %s >startLatLng == null? %s >myLocationMarker.getPosition %s",
startPoint == null,
startLatLng == null,
myLocationMarker == null ? null : myLocationMarker.getPosition())));
return;
}
// final LinearInterpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
// float t = interpolator.getInterpolation((float) elapsed / duration);
float t = Math.min(elapsed / duration, 1f);
double lng = t * target.longitude + (1 - t) * startLatLng.longitude;
double lat = t * target.latitude + (1 - t) * startLatLng.latitude;
myLocationMarker.setPosition(new LatLng(lat, lng));
if (t < 1.0) {
// Post again 10ms later.
handler.postDelayed(this, 10);
}
}
});
}
示例13: animateMarker
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
public void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) {
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;
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 {
if (hideMarker) {
marker.setVisible(false);
} else {
marker.setVisible(true);
}
}
}
});
}
示例14: drawYMetric
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
private void drawYMetric(Canvas canvas, Paint textPaint, Paint barPaint) {
Projection projection = mMap.getProjection();
if (projection != null) {
Location locationP1 = new Location("ScaleBar location p1");
Location locationP2 = new Location("ScaleBar location p2");
LatLng p1 = projection.fromScreenLocation(new Point(getWidth() / 2,
(int) ((getHeight() / 2) - (mYdpi / 2))));
LatLng p2 = projection.fromScreenLocation(new Point(getWidth() / 2,
(int) ((getHeight() / 2) + (mYdpi / 2))));
locationP1.setLatitude(p1.latitude);
locationP2.setLatitude(p2.latitude);
locationP1.setLongitude(p1.longitude);
locationP2.setLongitude(p2.longitude);
float yMetersPerInch = locationP1.distanceTo(locationP2);
if (mIsLongitudeBar) {
String yMsg = scaleBarLengthText(yMetersPerInch);
Rect yTextRect = new Rect();
textPaint.getTextBounds(yMsg, 0, yMsg.length(), yTextRect);
int textSpacing = (int) (yTextRect.height() / 5.0);
canvas.drawRect(mXOffset, mYOffset, mXOffset + mLineWidth, mYOffset + mYdpi, barPaint);
canvas.drawRect(mXOffset, mYOffset + mYdpi, mXOffset + yTextRect.height() +
mLineWidth + textSpacing, mYOffset + mYdpi + mLineWidth, barPaint);
if (!mIsLatitudeBar) {
canvas.drawRect(mXOffset, mYOffset, mXOffset + yTextRect.height() +
mLineWidth + textSpacing, mYOffset + mLineWidth, barPaint);
}
float x = mXOffset + yTextRect.height() + mLineWidth + textSpacing;
float y = mYOffset + mYdpi / 2 + yTextRect.width() / 2;
canvas.rotate(-90, x, y);
canvas.drawText(yMsg, x, y + textSpacing, textPaint);
}
}
}
示例15: drawXMetric
import com.google.android.gms.maps.Projection; //導入方法依賴的package包/類
private void drawXMetric(Canvas canvas, Paint textPaint, Paint barPaint) {
Projection projection = mMap.getProjection();
if (projection != null) {
int point1, point2;
point1 = (int) (((getWidth() / 2) - (mXdpi / 2)));
point2 = (int) (getHeight() / 2);
LatLng p1 = projection.fromScreenLocation(
new Point(point1, point2));
int point3, point4;
point3 = (int) (((getWidth() / 2) + (mXdpi / 2)));
point4 = (int) (getHeight() / 2);
LatLng p2 = projection.fromScreenLocation(
new Point(point3, point4));
Location locationP1 = new Location(SCALEBAR_LOCATION_PART_1);
Location locationP2 = new Location(SCALEBAR_LOCATION_PART_2);
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, mIsImperial, mIsNautical);
Rect xTextRect = new Rect();
textPaint.getTextBounds(xMsg, 0, xMsg.length(), xTextRect);
int textSpacing = (int) (xTextRect.height() / 5.0);
if(drawLine) {
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) {
if(drawLine) {
canvas.drawRect(mXOffset, mYOffset, mXOffset + mLineWidth, mYOffset +
xTextRect.height() + mLineWidth + textSpacing, barPaint);
}
}
if(drawNumbers) {
canvas.drawText(xMsg, (mXOffset + mXdpi / 2 - xTextRect.width() / 2),
(mYOffset + xTextRect.height() + mLineWidth + textSpacing), textPaint);
}
}
}
}