Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:05:30+00:00 2026-05-23T10:05:30+00:00

I am trying to find distance between two locations in android using the LocationListener

  • 0

I am trying to find distance between two locations in android using the LocationListener and related classes and methods.

  1. I was able to get the coordinates of the given address by using geo coding class. And also was able to get distance between two addresses using the distanceto method.

2.Now I want to give address and get coordinates and then get the distance between previous given address location and the current location (which changes) in real time. since there is no current location method in android i got to use Location Listener.

  1. the want the distance between the given address location coordinate and the real time changing location when moving using locationlistener and other location classes and methods. I wrote and deployed on a device with all permissions in manifest, but the gps gets disabled as soon as i start the app. Below is my code

//below code to get the address location coordinates which is succesful

int i=1;
    Geocoder geo=new Geocoder(this);
    List<Address> addressList = geo.getFromLocationName(adrs,i);
    Address address = addressList.get(0);
    if(address.hasLatitude() && address.hasLongitude()){
          lat = address.getLatitude();
          lon = address.getLongitude(); 
        String adlalo= "Latitude of above address: "+lat +"             " +
        "                     "+"Longitude of above address: "+lon;
        t2.setText(adlalo);
    }

// and below is the location listener class

public class LoctListner implements LocationListener
{
       public void onLocationChanged(Location loc)
    {  
      t3 = (TextView) findViewById(R.id.textView3);  
      l1.setLatitude(lat);
  l1.setLongitude(lon);  


        float d=l1.distanceTo(loc);
        String s="the distance between starting and ending point is "+d;
        t3.setText(s);

 }    

}

help me where i made the mistake. Unable to see the log since i got to take the device out to test.since this app needs a moving location.Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:05:30+00:00Added an answer on May 23, 2026 at 10:05 am

    Unable to see the log since i got to take the device out to test.since this app needs a moving location

    Perhaps you forgot to call requestLocationUpdates() ?

    Unable to see the log

    You have not put any Logs . Use Logs.D(“YOURTAG”, “Logs statements”);

      Location l2 = new Location("");
      l2.setLatitude(loc.getLatitude());
      l2.setLongitude(loc.getLongitude());
    

    ^ This is not required

     float door = l1.distanceTo(loc);
    

    You have to wait for a few minutes till the GPS Icon stops animating. This means that a fix has been attained. So check if loc is null

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find the distance between two longitude and latitude points. I
I'm trying to find the distance between two points (for which I've latitudes &
Dijkstra's is typically used to find the shortest distance between two nodes in a
Trying to work out distance between two points (lat & lng) I have an
I'm looking for a formula to find the shortest distance in degrees between two
I am trying to find the distance between 2 points, one being from user
Trying to find an example that has css rollover using sprites & sliding door
I'm trying to implement the distance matrix in parallel using openmp in which I
I've just started using Google's search API to find addresses and the distances between
I need a basic function to find the shortest distance between a point and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.