Ejemplo n.º 1
0
  // ---------------------------------------------------------------------------------------------
  // Method for finding the nearest vet. ---------------------------------------------------------
  private void findNearestVet() {
    Double tempVetLat, tempVetLng;
    LatLng tempVetLatLng;
    String tempVetName;
    float minimumDistance = 0;
    nearestVetPosition = 0;
    Log.d("VetFirstActivity", "ready to read the data from the list");
    if (vetList != null) {
      for (int i = 0; i < vetList.size(); i++) {
        tempVetLat = vetList.get(i).getLat();
        tempVetLng = vetList.get(i).getLng();
        tempVetName = vetList.get(i).getName();
        Log.d(
            "VetFirstActivity",
            "(#" + i + ") " + tempVetName + "(" + tempVetLat + ", " + tempVetLng + ")");
        markerOptionsList.add(
            new MarkerOptions().position(new LatLng(tempVetLat, tempVetLng)).title(tempVetName));
        Log.d("VetFirstActivity", "added an item to markerOptionsList");

        tempVetLatLng = new LatLng(tempVetLat, tempVetLng);

        float[] distance_results = new float[2];
        Location.distanceBetween(
            currentLocationLatLng.latitude,
            currentLocationLatLng.longitude,
            tempVetLatLng.latitude,
            tempVetLatLng.longitude,
            distance_results);
        Log.d(
            "VetFirstActivity",
            "distance: "
                + distance_results[0]
                + " m - initial bearing: "
                + distance_results[1]
                + " degrees");

        if (i == 0) {
          minimumDistance = distance_results[0];
        } else if (minimumDistance > distance_results[0]) {
          minimumDistance = distance_results[0];
          nearestVetPosition = i;
        }
      }
    } else {
      Log.d("VetFirstActivity", "empty vetList");
    }
    nearestVet = vetList.get(nearestVetPosition);
    nearestVetLatLng = new LatLng(nearestVet.getLat(), nearestVet.getLng());
    Log.d(
        "VetFirstActivity",
        "nearest vet is: " + nearestVet.getName() + "(" + nearestVet.getTelephone() + ")");
  }
Ejemplo n.º 2
0
 // ---------------------------------------------------------------------------------------------
 // Method for updating the info of the vet that we're focused on. ------------------------------
 private void updateBasicVetInfo(final Vet vet) {
   vetName = (TextView) findViewById(R.id.vet_fir_name);
   vetName.setText(vet.getName());
   vetAddress = (TextView) findViewById(R.id.vet_fir_address);
   vetAddress.setText(vet.getAddress());
   vetCallButton = (ImageButton) findViewById(R.id.vet_fir_call_button);
   vetPhoneNumber = "tel:" + vet.getTelephone();
   vetCallButton.setOnClickListener(
       new View.OnClickListener() {
         @Override
         public void onClick(View v) {
           AppServices.loggingAction(
               loggedInUserID, activityTag, getString(R.string.act_vet_call_tag), vet.getVetID());
           Intent call_intent = new Intent(Intent.ACTION_CALL, Uri.parse(vetPhoneNumber));
           startActivity(call_intent);
         }
       });
 }