当前位置: 首页>>代码示例>>Java>>正文


Java SphericalUtil类代码示例

本文整理汇总了Java中com.google.maps.android.SphericalUtil的典型用法代码示例。如果您正苦于以下问题:Java SphericalUtil类的具体用法?Java SphericalUtil怎么用?Java SphericalUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SphericalUtil类属于com.google.maps.android包,在下文中一共展示了SphericalUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatDistanceBetween

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
public static String formatDistanceBetween(LatLng point1, LatLng point2) {
    if (point1 == null || point2 == null) {
        return null;
    }
    int distanceint;
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    double distance = Math.round(SphericalUtil.computeDistanceBetween(point1, point2));

    // Adjust to KM if M goes over 1000 (see javadoc of method for note
    // on only supporting metric)
    if (distance >= 1000) {
        numberFormat.setMaximumFractionDigits(1);

        String dis = String.valueOf(distance / 1000);
        if(dis.length()>=6)
        {
          distanceint = (int) (distance /1000);
            return numberFormat.format(distanceint) + DISTANCE_KM_POSTFIX;}
        else


        return numberFormat.format(distance/1000) + DISTANCE_KM_POSTFIX;
    }
    return numberFormat.format(distance) + DISTANCE_M_POSTFIX;
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:26,代码来源:Utils.java

示例2: buildClickBoundingBox

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
/**
 * Build a bounding box using the location coordinate click location and map view bounds
 *
 * @param latLng    click location
 * @param mapBounds map bounds
 * @return bounding box
 * @since 1.2.7
 */
public BoundingBox buildClickBoundingBox(LatLng latLng, BoundingBox mapBounds) {

    // Get the screen width and height a click occurs from a feature
    double width = TileBoundingBoxMapUtils.getLongitudeDistance(mapBounds) * screenClickPercentage;
    double height = TileBoundingBoxMapUtils.getLatitudeDistance(mapBounds) * screenClickPercentage;

    LatLng leftCoordinate = SphericalUtil.computeOffset(latLng, width, 270);
    LatLng upCoordinate = SphericalUtil.computeOffset(latLng, height, 0);
    LatLng rightCoordinate = SphericalUtil.computeOffset(latLng, width, 90);
    LatLng downCoordinate = SphericalUtil.computeOffset(latLng, height, 180);

    BoundingBox boundingBox = new BoundingBox(leftCoordinate.longitude, downCoordinate.latitude, rightCoordinate.longitude, upCoordinate.latitude);

    return boundingBox;
}
 
开发者ID:ngageoint,项目名称:geopackage-android-map,代码行数:24,代码来源:FeatureOverlayQuery.java

示例3: getLongitudeDistance

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
/**
 * Get the longitude distance in the middle latitude
 *
 * @param minLongitude min longitude
 * @param maxLongitude max longitude
 * @param latitude     latitude
 * @return distance
 * @since 1.2.7
 */
public static double getLongitudeDistance(double minLongitude,
                                          double maxLongitude,
                                          double latitude) {
    LatLng leftMiddle = new LatLng(latitude, minLongitude);
    LatLng middle = new LatLng(latitude, (minLongitude + maxLongitude) / 2.0);
    LatLng rightMiddle = new LatLng(latitude, maxLongitude);

    List<LatLng> path = new ArrayList<LatLng>();
    path.add(leftMiddle);
    path.add(middle);
    path.add(rightMiddle);

    double lonDistance = SphericalUtil.computeLength(path);
    return lonDistance;
}
 
开发者ID:ngageoint,项目名称:geopackage-android-map,代码行数:25,代码来源:TileBoundingBoxMapUtils.java

示例4: 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");
}
 
开发者ID:fwtrailsapp,项目名称:Android,代码行数:22,代码来源:RecordActivityFragment.java

示例5: formatDistanceBetween

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
/**
 * Calculate distance between two LatLng points and format it nicely for
 * display. As this is a sample, it only statically supports metric units.
 * A production app should check locale and support the correct units.
 */
public static String formatDistanceBetween(LatLng point1, LatLng point2) {
    if (point1 == null || point2 == null) {
        return null;
    }

    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    double distance = Math.round(SphericalUtil.computeDistanceBetween(point1, point2));

    // Adjust to KM if M goes over 1000 (see javadoc of method for note
    // on only supporting metric)
    if (distance >= 1000) {
        numberFormat.setMaximumFractionDigits(1);
        return numberFormat.format(distance / 1000) + DISTANCE_KM_POSTFIX;
    }
    return numberFormat.format(distance) + DISTANCE_M_POSTFIX;
}
 
开发者ID:TrekIndia,项目名称:TrekIndiaMobile,代码行数:22,代码来源:Utils.java

示例6: loadAttractionsFromLocation

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
private static List<Attraction> loadAttractionsFromLocation(final LatLng curLatLng) {
    String closestCity = TouristAttractions.getClosestCity(curLatLng);
    if (closestCity != null) {
        List<Attraction> attractions = ATTRACTIONS.get(closestCity);
        if (curLatLng != null) {
            Collections.sort(attractions,
                    new Comparator<Attraction>() {
                        @Override
                        public int compare(Attraction lhs, Attraction rhs) {
                            double lhsDistance = SphericalUtil.computeDistanceBetween(
                                    lhs.location, curLatLng);
                            double rhsDistance = SphericalUtil.computeDistanceBetween(
                                    rhs.location, curLatLng);
                            return (int) (lhsDistance - rhsDistance);
                        }
                    }
            );
        }
        return attractions;
    }
    return null;
}
 
开发者ID:TrekIndia,项目名称:TrekIndiaMobile,代码行数:23,代码来源:AttractionListFragment.java

示例7: 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;
}
 
开发者ID:TrekIndia,项目名称:TrekIndiaMobile,代码行数:21,代码来源:TouristAttractions.java

示例8: setPlaceAutoCompleteAdapterBounds

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
private void setPlaceAutoCompleteAdapterBounds(LatLng center) {
    // Add 2 points 1000m northEast and southWest of the center.
    // They increase the bounds only, if they are not already larger than this.
    // 1000m on the diagonal translates into about 709m to each direction.
    LatLng northEast = SphericalUtil.computeOffset(center, 709, 45);
    LatLng southWest = SphericalUtil.computeOffset(center, 709, 225);
    LatLngBounds bounds = new LatLngBounds.Builder()
            .include(northEast)
            .include(southWest)
            .build();

    if (placeAutoCompleteAdapter == null) {
        placeAutoCompleteAdapter = new PlaceAutoCompleteAdapter(
                this,
                android.R.layout.simple_dropdown_item_1line,
                googleApiClient,
                bounds);
    }
}
 
开发者ID:SenAndAaron,项目名称:voyager2-android,代码行数:20,代码来源:GoogleApiClientActivity.java

示例9: 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);
    }
}
 
开发者ID:TruckMuncher,项目名称:TruckMuncher-Android,代码行数:19,代码来源:CustomerMapFragment.java

示例10: 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;
}
 
开发者ID:typebrook,项目名称:FiveMinsMore,代码行数:37,代码来源:TrackingService.java

示例11: 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);
}
 
开发者ID:ngageoint,项目名称:geopackage-android-map,代码行数:36,代码来源:GoogleMapShapeMarkers.java

示例12: 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;
}
 
开发者ID:ngageoint,项目名称:geopackage-android-map,代码行数:16,代码来源:TileBoundingBoxMapUtils.java

示例13: showLineCharts

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
private void showLineCharts() {
    List<Entry> altitudeEntries = new ArrayList<>();
    List<Entry> speedEntries = new ArrayList<>();
    BRecord lastRecord = null;

    final List<ILatLonRecord> trackPoints = igcFile.getTrackPoints();
    int index;
    int lastIndexShown = 0;

    for (index = 0; index < trackPoints.size(); index++) {
        BRecord bRecord = (BRecord) trackPoints.get(index);

        if (index % Constants.Chart.POINTS_SIMPLIFIER == 0) {
            altitudeEntries.add(new Entry(index, bRecord.getAltitude()));
        }

        if (index % Constants.Chart.POINTS_SIMPLIFIER == 0) {
            if (lastRecord == null) {
                lastRecord = (BRecord) trackPoints.get(0);
            }
            double distanceBetween = SphericalUtil.computeLength(Utilities.getLatLngPoints(trackPoints.subList(lastIndexShown, index)));
            long timeBetween = Utilities.getDiffTimeInSeconds(lastRecord.getTime(), bRecord.getTime());
            int averageSpeed = Utilities.calculateAverageSpeed(distanceBetween, timeBetween);

            speedEntries.add(new Entry(index, averageSpeed));
            lastRecord = bRecord;
            lastIndexShown = index;
        }
    }

    //Hack to always graph at altitude and speed where the glider has landed after the graph is simplified
    altitudeEntries.add(new Entry(index + 1, ((BRecord) igcFile.getTrackPoints().get(igcFile.getTrackPoints().size() - 1)).getAltitude()));
    speedEntries.add(new Entry(index + 1, 0));

    setupGraphic(altitudeLineChart, altitudeEntries, igcFile.getMinAltitude(), new AltitudeGrphicFormatter());
    setupGraphic(speedLineChart, speedEntries, 0, new SpeedGrphicFormatter());
}
 
开发者ID:santiago-hollmann,项目名称:igcparser,代码行数:38,代码来源:FlightInformationActivity.java

示例14: animateMarker

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
private void animateMarker() {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    duration = 300000;

    final Interpolator interpolator = new LinearInterpolator();

    handler.post(new Runnable() {
        int i = 0;

        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            if (i < listLatLngPoints.size()) {
                Double heading = SphericalUtil.computeHeading(markerGlider.getPosition(), listLatLngPoints.get(i));
                markerGlider.setRotation(heading.floatValue());
                markerGlider.setPosition(listLatLngPoints.get(i));
            }
            i++;

            if (t < 1.0 && i < listLatLngPoints.size() && !isFinishReplay) {
                handler.postDelayed(this, replaySpeed);
            } else {
                finishReplay();
            }
        }
    });
}
 
开发者ID:santiago-hollmann,项目名称:igcparser,代码行数:30,代码来源:FlightPreviewActivity.java

示例15: calculateTaskDistance

import com.google.maps.android.SphericalUtil; //导入依赖的package包/类
public static double calculateTaskDistance(List<ILatLonRecord> waypoints) {
    ArrayList<ILatLonRecord> listCRecord = new ArrayList<>();
    for (ILatLonRecord waypoint : waypoints) {
        CRecordWayPoint cRecord = (CRecordWayPoint) waypoint;
        if (cRecord.getType() != CRecordType.LANDING && cRecord.getType() != CRecordType.TAKEOFF) {
            listCRecord.add(cRecord);
        }
    }
    return SphericalUtil.computeLength(Utilities.getLatLngPoints(listCRecord));
}
 
开发者ID:santiago-hollmann,项目名称:igcparser,代码行数:11,代码来源:WaypointUtilities.java


注:本文中的com.google.maps.android.SphericalUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。