title: Nearest OSM (open street map) node to my GPS coordinates
body: <p>I am working with open street maps. Now i can get all the intersection points in the map and can get their longitude and latitude.. also i have GPS in my application
  what i want to do is find the nearest intersection point to my GPS coordinates 
  This is my method but it is not very accurate . I just need help to know why ! thanks..</p>
  
  <pre><code>public Nodee nearestPoint(double longitude, double latitude) throws Exception {
      inters = new ArrayList&lt;Nodee&gt;();
      inters = getIntersections();
  
      double minLong = Math.abs(longitude - (inters.get(0).lon));
      double minLat = Math.abs(latitude - (inters.get(0).lat));
      Nodee NearestNodeLong = null;
      Nodee NearestNodeLat = null;
  
      for (int i = 0; i &lt; inters.size(); i++) {
          if (Math.abs((inters.get(i).lon) - longitude) &lt; minLong) {
              minLong = (Math.abs((inters.get(i).lon) - longitude));
              NearestNodeLong = inters.get(i);
      } 
          if (Math.abs((inters.get(i).lat) - latitude) &lt; minLat) {
              minLat = Math.abs((inters.get(i).lat) - latitude);
              NearestNodeLat = inters.get(i);
          } 
  
      }
      if (NearestNodeLong.equals(NearestNodeLat)) {
          return NearestNodeLong;
      } else if (!NearestNodeLong.equals(NearestNodeLat)) {
          Double d1 = (double) distFrom(latitude, longitude, (NearestNodeLat.lat),
                  (NearestNodeLat.lon));
  
          Double d2 = (double) distFrom(latitude, longitude, (NearestNodeLong.lat),
                  (NearestNodeLong.lon));
  
          if (d1 &lt; d2)
              return NearestNodeLat;
          else if (d2 &lt; d1)
              return NearestNodeLong;
  
      }
      return null;
  
  }
  </code></pre>