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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:51:03+00:00 2026-05-28T04:51:03+00:00

I have been developing an android application for a gas station company. The application

  • 0

I have been developing an android application for a gas station company. The application uses google map.

The user selects two points on the map and i show the route between selected points.
The application needs to show nearest(in 2 miles radius) gas stations on the selected route.

The route is a coordinate array like:
Route[5000] = {“lon1,lat1″,”lon2,lat2″,”lon3,lat3”,”lon4,lat5″… }

And i have a gas stations list which consists of coordinates.
GasStations[200] = {“lon1,lat1″,”lon2,lat2″,”lon3,lat3”,”lon4,lat5″… }

Can you suggest me a high performance algorithm for calculating the nearest gas stations on the route.

Thanks.

  • 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-28T04:51:03+00:00Added an answer on May 28, 2026 at 4:51 am

    I am not familiar with android. Here the C# method to calculate the distance between two pairs of location. If distance is within 2 miles radius, pick that station.

    Yes, you will have to loop through 5000×200 = 1,000,000, but it is quite fast.

    I hope that will help.

    decimal distance = CalculateDistance(stationLatitude, stationLongitude, routeLatitude, routeLongitude);
    
    private static double ToRadian(double val)
    {
        return (Math.PI / 180) * val;
    }
    
    private static double ToXAxis(decimal lat, decimal lng)
    {
        return (Math.Cos(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lat) *
            Math.Cos(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lng));
    }
    
    private static double ToYAxis(decimal lat, decimal lng)
    {
        return (Math.Cos(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lat) *
            Math.Sin(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lng));
    }
    
    private static double ToZAxis(decimal lat)
    {
        return Math.Sin(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lat);
    }
    
    private static decimal CalculateDistance(decimal lat1, decimal lng1, decimal lat2, decimal lng2)
    {
        double cntXAxis = Math.Cos(ToRadian((double) lat1))*Math.Cos(ToRadian((double) lng1));
        double cntYAxis = Math.Cos(ToRadian((double) lat1))*Math.Sin(ToRadian((double) lng1));
        double cntZAxis = Math.Sin(ToRadian((double) lat1));
    
        return (decimal) (3961*Math.Acos(ToXAxis(lat2, lng2)*cntXAxis + ToYAxis(lat2, lng2)*cntYAxis + ToZAxis(lat2)*cntZAxis));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing Android application, and I have one question - ListView uses
I have been developing Android application where I use this code: Date d=new Date(new
I have been developing Android application and I can't make 1 thing - my
I have been developing Android application which has 3 ListView and one ContextMenu for
I have been developing Android application since 3 to 4 months. I am naive,
I have been developing an Android application and testing the orientation sensor using SensorSimulator
I have been developing a C# windows form application in XP. It all works
I have been developing an Android app and testing with a 1.5 AVD and
I have been developing Android apps, but never did a live wallpaper. I have
I have been developing an Android app. I would like to hide the OK

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.