Android Distance Calculate getClosestStore(ArrayList storeIds, SparseArray distanceMap)

Here you can find the source of getClosestStore(ArrayList storeIds, SparseArray distanceMap)

Description

get Closest Store

Declaration

public static int getClosestStore(ArrayList<Integer> storeIds,
            SparseArray<Float> distanceMap) 

Method Source Code

//package com.java2s;

import android.util.SparseArray;

import java.util.ArrayList;

public class Main {
    public static int getClosestStore(ArrayList<Integer> storeIds,
            SparseArray<Float> distanceMap) {
        /*//w  ww  .java2  s .c  om
         * storeIds: list of store_ids
         * distanceMap: <store_id, distance>
         * 
         * Returns the store_id of the store with the minimal distance from the user's last known location
         */
        float closestDistance = -1;
        int closestStore = 0;
        if (storeIds != null && distanceMap != null) {
            for (int j = 0; j < storeIds.size(); j++) {
                float nextDistance = distanceMap.get(storeIds.get(j));
                if (closestDistance < 0 || nextDistance < closestDistance) {
                    closestDistance = nextDistance;
                    closestStore = storeIds.get(j);
                }
            }
        }
        return closestStore;
    }
}

Related

  1. getMessageForDistance(long distance)
  2. calculateEte(boolean useBearing, double distance, double speed, double bearing, double heading)
  3. fetchRawEte(boolean useBearing, double distance, double speed, double bearing, double heading)
  4. distance(double lat1, double lon1, double lat2, double lon2, char unit)
  5. computeSpeed(int distance, long duration)
  6. toDistanceSearchUri(Uri contentUri, Location location, double distance)
  7. getDisplay(Activity activity)