With this rule, how do I view the point closer to my location

Asked

Viewed 115 times

1

Button button = (Button) convertView.findViewById(R.id.buttonComoChegar);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        String latitude = itemPosicao.getLatitude();
        String longitude = itemPosicao.getLongitude();

        String strUri = "http://maps.google.com/maps?q=loc:" + latitude + "," + longitude;
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(strUri));

        intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");

        context.startActivity(intent);

    }
});

This list is searching the latitude and longitude of the Bank, what I wanted is for the nearest user to appear to me by latitude and longitude.

inserir a descrição da imagem aqui

  • 4
  • that doesn’t solve...

  • See if it helps you: http://answall.com/questions/13061/howto rescues%C3%A7%C3%A3o-gps-in-coordinates-all-Usu%C3%A1rios-do-aplicati

  • Like, I have a listview showing some users and that there shows the one button to go to the user’s location, only that this list wanted to show from the nearest point ie if up down without the user knowing. The list would show users closer.

1 answer

0

Calculating the distance between 2 points

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
double earthRadius = 3958.75; // miles (or 6371.0 kilometers)
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double sindLat = Math.sin(dLat / 2);
double sindLng = Math.sin(dLng / 2);
double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2)
        * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;

return dist;
}

source: https://stackoverflow.com/questions/120283/how-can-i-measure-distance-and-create-a-bounding-box-based-on-two-latitudelongi

You can also check this link: https://stackoverflow.com/questions/22577075/calculating-the-distance-between-two-latitude-and-longitude-points-in-android

Browser other questions tagged

You are not signed in. Login or sign up in order to post.