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 6119331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:32:25+00:00 2026-05-23T15:32:25+00:00

I encounter some issues on trying to calculate distance between one location and a

  • 0

I encounter some issues on trying to calculate distance between one location and a list of others (in order to get the closest one).
I tried by using Location.distanceBetween(…) and location.distanceTo(…), the two method are working but both of them send me different data and not any of them seems right.

My data came from a Class ConcessionDistance which is a basic extension of HashMap containing location data (as integer convert as string) and some other stuff that we don’t need here.

private ArrayList<ConcessionDistance> getMapsConcessionsDistancesFromPoint(ArrayList<ConcessionDistance> al, Location currentLocation) {
    Location dest;
    float distance1,distance2;
    float[] curDist = new float[1];
    double lati,longi;
    Log.i("DBTableConcessions","getMapsConcessionsDistancesFromPoint: Generation d'une map de donnée de concession");
    for(ConcessionDistance curConc : al){
        //Distance by method 1
        dest = new Location(LOCATION_PROVIDER);
        lati = new Double((new Integer(curConc.get("concession_latitude"))) /1e6);
        longi = new Double((new Integer(curConc.get("concession_longitude"))) /1e6);
        dest.setLatitude(lati);
        dest.setLongitude(longi);
        distance1 = currentLocation.distanceTo(dest);
        //Distance by method2
        Location.distanceBetween(
            currentLocation.getLatitude(), 
            currentLocation.getLongitude(), 
            (double) ((new Integer(curConc.get("concession_latitude"))) /1000000), 
            (double) ((new Integer(curConc.get("concession_longitude"))) /1000000),
            curDist);
        distance2 = curDist[0];
        Log.i("DBTableConcessions","distance :"+distance1+" ou "+distance2);//+" ,lat :"+lati+" ,long "+longi);  //+"curDist{0="+curDist[0]+",1="+curDist[1]+",2="+curDist[2]+"}"
        //Saving one of the distance
        curConc.put("distance",String.valueOf(distance1));
    }
    return al;
}

Can some one help me, to figure out where is the problem?
I think of a conversion problem but I’m to deep in the problem to solve it myself 🙁

Any help will be welcome. Thanks by advance.

Edit: Here is part of my LogCat: I send to the emulator the gps location of “Strasbourg” (those are cities from east-france) and process distance to all those cities:

06-29 06:37:37.215: INFO/DBTableConcessions(809): distance from EVRY :346254.66 ou 373061.38
06-29 06:37:37.235: INFO/DBTableConcessions(809): distance from HAGUENAU CEDEX :105491.984 ou 0.0
06-29 06:37:37.235: INFO/DBTableConcessions(809): distance from BESANCON CEDEX :110127.08 ou 134302.03
06-29 06:37:37.265: INFO/DBTableConcessions(809): distance from BREST CEDEX 9 :852829.1 ou 820181.7
06-29 06:37:37.295: INFO/DBTableConcessions(809): distance from HOENHEIM :87783.39 ou 0.0
06-29 06:37:37.326: INFO/DBTableConcessions(809): distance from COLMAR :28067.428 ou 0.0
06-29 06:37:37.355: INFO/DBTableConcessions(809): distance from BELFORT :40919.13 ou 134302.03
06-29 06:37:37.446: INFO/DBTableConcessions(809): distance from SARREBOURG :81606.31 ou 0.0

The real distance (given by google maps) between those cities and “Strasbourg” are :
Evry : 520km ( method1 : miss 175km, method2 : miss 145km)
Haguenau : 30km ( method1: add 70km, method2: return 0)
Besancon : 250km (method1: miss 140km, method2: miss 120km)
Brest : 1070km (method1: miss 200km, method2: miss 230km)
Hoenheim : 5km (method1: add 80km, method2: return 0)
Colmar : 75km (method1: miss 50km, method2: return 0)
Belfort : 155km (method1: miss 110km, method2: miss 20km)
Sarrebourg : 75km (method1: miss 5km, method2: return 0)

So we can notice that the second method return 0 when real distance is below ~100km, wherease for the method1 I can’t see any logic inhere :/

  • 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-23T15:32:26+00:00Added an answer on May 23, 2026 at 3:32 pm

    Ok, so correction for this problem is :
    first I needed to enter correct value in my lati,longi. This can be done with:

     lati = Double.valueOf(curConc.get("concession_latitude"))/1000000;
    

    this way, all method give me the same distances, so the calculation method works fine.

    afterwards, the Location given in parameters wasn’t correct neither.
    In fact they don’t contains fractional data. So I know were is the problem but I do not know how to resolv it. In fact the line who gave me bad data are here

    final LocationManager manag = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                //Choix du service de localisation en fonction de critères
                Criteria crit = new Criteria();
                crit.setCostAllowed(false);
                crit.setAccuracy(100); //précis à 1km pret
                String choix_source = manag.getBestProvider(crit, true);
                //demander la position courante
                manag.requestLocationUpdates(choix_source, 10000, 0, new LocationListener(){ //toutes les 10 secondes
                    //Lors de la capture de la position
                    public void onLocationChanged(Location location) {
                    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
I am puzzled by some issues when trying to design interacting classes. If a
I frequently encounter some definitions for Win32API structures (but not limited to it) that
I am writing a form using jQuery and encounter some difficulties. My form works
I've encountered some errors when I tried to install an artifact manually with Maven
I have some trouble when trying to update a table by looping cursor which
I am trying to get a Date type field from the entity and I
I am having issues with ie 8 compatibility mode. I have some buttons that
Right now, I am trying to learn Scala . I've started small, writing some
I was very surprised to get this error today, as it's one that I've

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.