Suppose I have two GPS points (start and end points) each with lat/lon. I want to get equally spaced GPS points between start and end nodes. That is, I want to find GPS points for example every 10 meter from start node to end node.

Similar question is asked here. From the answers given I have referred the one by Vikram Gupta. This solution works fine but if you replace

int dist = (int) d / interval


int dist = (int) d

in getLocations(...) method some calculated coordinates lay beyond the end coordinate. How can the code be modified to prevent this?

  • Welcome to GIS SE. As a new user, please take the Tour. All questions should be standalone. You can reference another question, but the question itself should be a coherent whole. Please Edit this question so that it clear enough that someone else could answer it.
    – Vince
    Commented Jan 20, 2018 at 14:22

1 Answer 1


Here is the answer. Add the following method,

   public static boolean nodeInBetween(Node start, Node end, Node
 newNode) {
        if (start.getLatitude() < end.getLatitude()) {
             if (newNode.getLatitude()>end.getLatitude()) {
                return false;
         } else if (start.getLatitude() > end.getLatitude()) {
             if (newNode.getLatitude() < end.getLatitude()) {
                 >return false;
        >} else if (start.getLongitude() < end.getLongitude()) {
            if (newNode.getLongitude() > end.getLongitude()) {
                return false;
         } else if (start.getLongitude() > end.getLongitude()) {
             if (newNode.getLongitude() < end.getLongitude()) {
                 return false;
         return true;

and modify part of for loop of the getLocations(...) method as follows

        if (nodeInBetween(start, end, newNode)) {
        } else {

Note that: MockLocation Class is named Node (with getLatitude() and getLongitude() mehtods) in this code

  • How do you make the nodes 'equal distance'?
    – swatchai
    Commented Jan 20, 2018 at 14:41
  • Let me explain it using counter example. Suppose the start =1 and end = 10. You want to get all points from start to end 2 units apart (i.e. equal distance). The algorithm displays 1, 3, 5, 7, 9, 10. Therefore, here equal distance can be interpreted as equal intervals (the last interval may less than others)
    – Jan Jan
    Commented Jan 21, 2018 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.