本文整理汇总了Java中com.google.maps.android.SphericalUtil.computeDistanceBetween方法的典型用法代码示例。如果您正苦于以下问题:Java SphericalUtil.computeDistanceBetween方法的具体用法?Java SphericalUtil.computeDistanceBetween怎么用?Java SphericalUtil.computeDistanceBetween使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.maps.android.SphericalUtil
的用法示例。
在下文中一共展示了SphericalUtil.computeDistanceBetween方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: captureLaterCoordinate
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
/**
* This method changes the live statistic text views and churns data for the current recording
* @param updatedLocation
*/
private void captureLaterCoordinate(LatLng updatedLocation) {
line.setPoints(recordActivityModel.getCurrentLatLngs());
mMap.animateCamera(CameraUpdateFactory.newLatLng(updatedLocation));
Double caloriesBurned = BMR * recordActivityModel.getExerciseType().getMETValue() * secs / secondsPerHour / 25;
caloriesInt = caloriesBurned.intValue();
recordActivityModel.getDuration().tickInt();
durationSinceLastLocation = System.currentTimeMillis() - lastLocationTime;
lastLocationTime = System.currentTimeMillis();
tempDistance = SphericalUtil.computeDistanceBetween(lastLocation, updatedLocation) / metersPerMile;
recordActivityModel.addDistance(tempDistance);
distance.setText("Distance: " + String.valueOf(distanceFormat.format(recordActivityModel.getTotalDistance())) + " mi");
calories.setText("Calories: " + String.valueOf(calorieFormat.format(caloriesInt)));
// Duration is updated by runnable
currentSpeed = tempDistance / durationSinceLastLocation * 1000 * secondsPerHour;
speed.setText("Speed: " + speedFormat.format(currentSpeed) + " mph");
}
示例2: getClosestCity
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
public static String getClosestCity(LatLng curLatLng) {
if (curLatLng == null) {
// In debug build still return a city so some data is displayed
if (BuildConfig.DEBUG) {
return TEST_CITY;
}
return null;
}
double minDistance = 0;
String closestCity = null;
for (Map.Entry<String, LatLng> entry: CITY_LOCATIONS.entrySet()) {
double distance = SphericalUtil.computeDistanceBetween(curLatLng, entry.getValue());
if (minDistance == 0 || distance < minDistance) {
minDistance = distance;
closestCity = entry.getKey();
}
}
return closestCity;
}
示例3: onLocationChanged
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location) {
// if the current location is null, we haven't loaded the active trucks yet.
boolean trucksNeedLoading = currentLocation == null;
LatLng oldLocation = currentLocation;
currentLocation = new LatLng(location.getLatitude(), location.getLongitude());
if (trucksNeedLoading) {
loadActiveTrucks();
getActivity().startService(GetTruckProfilesService.newIntent(getActivity(), currentLocation.latitude, currentLocation.longitude));
}
if (oldLocation == null ||
SphericalUtil.computeDistanceBetween(oldLocation, currentLocation) > MIN_LOCATION_CHANGE) {
getLoaderManager().restartLoader(LOADER_TRUCKS, null, this);
}
}
示例4: onStartCommand
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
@WorkerThread
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
count++;
if (LocationResult.hasResult(intent)) {
// 從fusedLocationApi取得位置資料
LocationResult locationResult = LocationResult.extractResult(intent);
Location location = locationResult.getLastLocation();
if (location != null) {
succeed++;
// 若小於最小間距,則不紀錄該航跡
if (mTrkpts.size() > 1) {
double interval = SphericalUtil.computeDistanceBetween(
new LatLng(location.getLatitude(), location.getLongitude()),
new LatLng(mLastPosition.getLatitude(), mLastPosition.getLongitude()));
if (interval < DISTANCE_INTERVAL_FOR_TRKPTS)
return START_STICKY;
}
mTrkpts.add(location);
mLastPosition = location;
// Send Location Update to Activity
if (callBack != null)
callBack.getServiceData(location);
}
}
// Message for testing
Log.d(TAG, "Record Times: " + count + ", Succeed times: " + succeed +
", Points number: " + mTrkpts.size()
+ ", Time from start: " + (new Date().getTime() - startTime) / 1000);
return START_STICKY;
}
示例5: addMarkerAsPolygon
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
/**
* Polygon add a marker in the list of markers to where it is closest to the
* the surrounding points
*
* @param marker
* @param markers
*/
public static void addMarkerAsPolygon(Marker marker, List<Marker> markers) {
LatLng position = marker.getPosition();
int insertLocation = markers.size();
if (markers.size() > 2) {
double[] distances = new double[markers.size()];
insertLocation = 0;
distances[0] = SphericalUtil.computeDistanceBetween(position,
markers.get(0).getPosition());
for (int i = 1; i < markers.size(); i++) {
distances[i] = SphericalUtil.computeDistanceBetween(position,
markers.get(i).getPosition());
if (distances[i] < distances[insertLocation]) {
insertLocation = i;
}
}
int beforeLocation = insertLocation > 0 ? insertLocation - 1
: distances.length - 1;
int afterLocation = insertLocation < distances.length - 1 ? insertLocation + 1
: 0;
if (distances[beforeLocation] > distances[afterLocation]) {
insertLocation = afterLocation;
}
}
markers.add(insertLocation, marker);
}
示例6: getLatitudeDistance
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
/**
* Get the latitude distance
*
* @param minLatitude
* @param maxLatitude
* @return
*/
public static double getLatitudeDistance(double minLatitude,
double maxLatitude) {
LatLng lowerMiddle = new LatLng(minLatitude, 0);
LatLng upperMiddle = new LatLng(maxLatitude, 0);
double latDistance = SphericalUtil.computeDistanceBetween(lowerMiddle,
upperMiddle);
return latDistance;
}
示例7: refresh
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
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;
}
}
}
示例8: addPoint
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
/**
* Adds a new point, calculates the new distance and draws the point and a
* line to it
*
* @param p the new point
*/
void addPoint(final LatLng p) {
if (!trace.isEmpty()) {
lines.push(mMap.addPolyline(
new PolylineOptions().color(COLOR_LINE).width(LINE_WIDTH).add(trace.peek())
.add(p)));
distance += SphericalUtil.computeDistanceBetween(p, trace.peek());
}
points.push(drawMarker(p));
trace.push(p);
updateValueText();
}
示例9: onTruckDataLoaded
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
private void onTruckDataLoaded(String name, String keywords, String imageUrl, String headerColor, LatLng truckLocation) {
if (TextUtils.isEmpty(imageUrl)) {
truckImage.setVisibility(View.GONE);
} else {
Picasso.with(getActivity())
.load(imageUrl)
.fit()
.centerInside()
.transform(new CircleTransform())
.into(truckImage);
}
if (headerColor != null) {
headerView.setBackgroundColor(Color.parseColor(headerColor));
int textColor = ColorCorrector.calculateTextColor(headerColor);
truckName.setTextColor(textColor);
truckKeywords.setTextColor(textColor);
}
truckName.setText(name);
truckKeywords.setText(keywords);
if (referenceLocation != null) {
// distance in meters
double delta = SphericalUtil.computeDistanceBetween(truckLocation, referenceLocation);
// convert to miles
delta *= METERS_TO_MILES;
distanceFromLocation.setText(new DecimalFormat("0.0").format(delta) + " mi");
distanceFromLocation.setVisibility(View.VISIBLE);
} else {
distanceFromLocation.setVisibility(View.GONE);
}
}
示例10: bindView
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
private void bindView(Cursor data) {
Utils.logD(LOG_TAG,"bindView");
mFarmaciasList=new ArrayList<>();
if (data.isClosed()) return;
if (data.moveToFirst()) {
do {
Pharmacy farmacia = new Pharmacy();
double latDest = data.getDouble(data.getColumnIndex(DbContract.FarmaciasEntity.LAT));
double lonDest = data.getDouble(data.getColumnIndex(DbContract.FarmaciasEntity.LON));
double distance = SphericalUtil.computeDistanceBetween(new LatLng(latDest,lonDest),
new LatLng(mLocation.getLatitude(),mLocation.getLongitude()));
// double distance = Utils.meterDistanceBetweenPoints(latDest, lonDest, mLocation.getLatitude(), mLocation.getLongitude());
farmacia.setName(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.NAME)));
farmacia.setAddress(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.ADDRESS)));
farmacia.setLocality(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.LOCALITY)));
farmacia.setProvince(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.PROVINCE)));
farmacia.setPostal_code(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.POSTAL_CODE)));
String phone = data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.PHONE));
farmacia.setPhone(phone);
farmacia.setLat(latDest);
farmacia.setLon(lonDest);
farmacia.setDistance(distance);
String hours = data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.HOURS));
farmacia.setHours(hours);
farmacia.setOpen(Utils.isPharmacyOpen(hours));
String addressFormatted = Utils.formatAddress(farmacia.getAddress(),
farmacia.getPostal_code(),
farmacia.getLocality(),
farmacia.getProvince());
farmacia.setAddressFormatted(addressFormatted);
boolean favorite;
int j=data.getInt(data.getColumnIndex(DbContract.FarmaciasEntity.FAVORITE));
if (j==0){
favorite=false;
} else {
favorite=true;
}
farmacia.setFavorite(favorite);
mFarmaciasList.add(farmacia);
} while (data.moveToNext());
}
mFarmaciasList = toFilteredSortedOrderedList(mFarmaciasList);
mainHandler.post(new Runnable() {
@Override
public void run() {
mView.hideLoading();
if(mFarmaciasList !=null && mFarmaciasList.size()>0) {
mView.showResults(mFarmaciasList);
} else {
mView.showNoResults();
}
}
});
}
示例11: transformSearchCursor
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
private List<Pharmacy> transformSearchCursor(Cursor data){
List<Pharmacy> list = new ArrayList<Pharmacy>(data.getCount());
if(data.moveToFirst()) {
do {
Pharmacy farmacia = new Pharmacy();
farmacia.setName(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.NAME)));
farmacia.setAddress(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.ADDRESS)));
farmacia.setLocality(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.LOCALITY)));
farmacia.setProvince(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.PROVINCE)));
farmacia.setPostal_code(data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.POSTAL_CODE)));
String phone = data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.PHONE));
farmacia.setPhone(phone);
farmacia.setPhoneFormatted(Utils.formatPhoneNumber(phone));
double latDest = data.getDouble(data.getColumnIndex(DbContract.FarmaciasEntity.LAT));
double lonDest = data.getDouble(data.getColumnIndex(DbContract.FarmaciasEntity.LON));
double distance = SphericalUtil.computeDistanceBetween(new LatLng(latDest,lonDest),
new LatLng(mLocation.getLatitude(),mLocation.getLongitude()));
//double distance = Utils.meterDistanceBetweenPoints(latDest, lonDest, mLocation.getLatitude(), mLocation.getLongitude());
farmacia.setLat(latDest);
farmacia.setLon(lonDest);
farmacia.setDistance(distance / 1000);
String hours = data.getString(data.getColumnIndex(DbContract.FarmaciasEntity.HOURS));
farmacia.setHours(hours);
farmacia.setOpen(Utils.isPharmacyOpen(hours));
String addressFormatted = Utils.formatAddress(farmacia.getAddress(),
farmacia.getPostal_code(),
farmacia.getLocality(),
farmacia.getProvince());
farmacia.setAddressFormatted(addressFormatted);
boolean favorite;
int j = data.getInt(data.getColumnIndex(DbContract.FarmaciasEntity.FAVORITE));
if (j == 0) {
favorite = false;
} else {
favorite = true;
}
farmacia.setFavorite(favorite);
list.add(farmacia);
} while (data.moveToNext());
}
return list;
}
示例12: addMarkerAsPolyline
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
/**
* Polyline add a marker in the list of markers to where it is closest to
* the the surrounding points
*
* @param marker
* @param markers
*/
public static void addMarkerAsPolyline(Marker marker, List<Marker> markers) {
LatLng position = marker.getPosition();
int insertLocation = markers.size();
if (markers.size() > 1) {
double[] distances = new double[markers.size()];
insertLocation = 0;
distances[0] = SphericalUtil.computeDistanceBetween(position,
markers.get(0).getPosition());
for (int i = 1; i < markers.size(); i++) {
distances[i] = SphericalUtil.computeDistanceBetween(position,
markers.get(i).getPosition());
if (distances[i] < distances[insertLocation]) {
insertLocation = i;
}
}
Integer beforeLocation = insertLocation > 0 ? insertLocation - 1
: null;
Integer afterLocation = insertLocation < distances.length - 1 ? insertLocation + 1
: null;
if (beforeLocation != null && afterLocation != null) {
if (distances[beforeLocation] > distances[afterLocation]) {
insertLocation = afterLocation;
}
} else if (beforeLocation != null) {
if (distances[beforeLocation] >= SphericalUtil
.computeDistanceBetween(markers.get(beforeLocation)
.getPosition(), markers.get(insertLocation)
.getPosition())) {
insertLocation++;
}
} else {
if (distances[afterLocation] < SphericalUtil
.computeDistanceBetween(markers.get(afterLocation)
.getPosition(), markers.get(insertLocation)
.getPosition())) {
insertLocation++;
}
}
}
markers.add(insertLocation, marker);
}
示例13: distance
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
private static double distance(LatLng a, LatLng b, LatLng c) {
return SphericalUtil.computeDistanceBetween(a, b) + SphericalUtil.computeDistanceBetween(b, c) + SphericalUtil.computeDistanceBetween(c, a);
}
示例14: createRouteAnimatorSet
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
/**
* Create a routeAnimator set with given @params
* WARNING: Current animation is to fast
*
* @param route to be followed
* @param map where the animation is going to occur
* @param cameraHeadingChangeRate self-explanatory
* @param marker "Avatar"/representation following the route
* @param animatorListener self explanatory
* @param animatorUpdateListener self explanatory
* @param animatorSetDuration set a specific duration for the AnimatorSet (0 for null)
* @param childDuration set a specific duration for AnimatorSet's child's (0 for null)
* @return should be .start() from the caller
*/
public static AnimatorSet createRouteAnimatorSet(LatLng[] route, final GoogleMap map, long cameraHeadingChangeRate,
Marker marker, Animator.AnimatorListener animatorListener,
ValueAnimator.AnimatorUpdateListener animatorUpdateListener,
long animatorSetDuration, long childDuration) {
// TODO: Fix movement speed
LinkedList<Animator> animators = new LinkedList<>();
// For each segment of the route, create one heading adjustment animator
// and one segment fly-over animator.
for (int i = 0; i < route.length - 1; i++) {
// If it the first segment, ensure the camera is rotated properly.
float h1;
if (i == 0) {
h1 = map.getCameraPosition().bearing;
} else {
h1 = (float) SphericalUtil.computeHeading(route[i - 1], route[i]);
}
float h2 = (float) SphericalUtil.computeHeading(route[i], route[i + 1]);
ValueAnimator va = ValueAnimator.ofFloat(h1, h2);
va.addUpdateListener(animatorUpdateListener);
// Use the change in degrees of the heading for the animation
// duration.
long d = Math.round(Math.abs(h1 - h2));
va.setDuration(d * cameraHeadingChangeRate);
animators.add(va);
ObjectAnimator oa = ObjectAnimator.ofObject(marker, "position",
new LatLngEvaluator(route[i], route[i + 1]), route[i], route[i + 1]);
oa.setInterpolator(new LinearInterpolator());
// TODO: Move this listener to calling activity
oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
LatLng target = (LatLng) animation.getAnimatedValue();
map.moveCamera(CameraUpdateFactory.newLatLng(target));
}
});
// Use the distance of the route segment for the duration.
double dist = SphericalUtil.computeDistanceBetween(route[i], route[i + 1]);
if (childDuration != 0) {
oa.setDuration(childDuration);
} else {
oa.setDuration(Math.round(dist) * 10);
}
animators.add(oa);
}
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(animators);
if (animatorSetDuration != 0) {
animatorSet.setDuration(animatorSetDuration);
}
animatorSet.addListener(animatorListener);
return animatorSet;
}
示例15: getLatLngDistance
import com.google.maps.android.SphericalUtil; //导入方法依赖的package包/类
public static double getLatLngDistance(LatLng posOne, LatLng posTwo) {
double distance = SphericalUtil.computeDistanceBetween(posOne, posTwo);
return distance;
}