     static func latLonToIndex(latLon:CLLocationCoordinate2D, boundingBox:AxisOrientedBoundingBox, resolution:Double) -> (Int, Int) {
         let llLat:Double = latLon.latitude
         let llLatGrid:Double = boundingBox.getLowerLeft().latitude
-        let xIndex:Int = Int(floor((llLat - llLatGrid)*resolution))
+        let yIndex:Int = Int(floor(roundMe((llLat - llLatGrid)*resolution)))
         
         let llLon:Double = latLon.longitude
         let llLonGrid:Double = boundingBox.getLowerLeft().longitude
-        let yIndex:Int = Int(floor((llLon - llLonGrid)*resolution))
+        let xIndex:Int = Int(floor(roundMe((llLon - llLonGrid)*resolution)))
         return (xIndex, yIndex)
+    }
+    
+    static private func roundMe(d:Double) -> Double {
+        let precision:Double = pow(10, 9)
+        return Double(round(precision*d)/precision)
     }
     
     /**

                var lowerRightIndex:(Int, Int) = hgtFileOfInterest.latLonToIndex(hgtAreaOfInterest.getLowerRight())
                
                // the files are enumerated from top to bottom, left to right, so flip the yIndex
                upperLeftIndex.1 = hgtFileOfInterest.getResolution() - upperLeftIndex.1
                lowerRightIndex.1 = hgtFileOfInterest.getResolution() - lowerRightIndex.1
                
                let data = NSData(contentsOfURL: hgtFileOfInterest.path)!
                
                NSLog("data.length \(data.length)")
                
                let dataRange = NSRange(location: 0, length: data.length)
                var elevation = [Int16](count: data.length, repeatedValue: Int16(Srtm.NO_DATA))
                data.getBytes(&elevation, range: dataRange)
                
                
            }
        }
        
        
        
    
//    
//        var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String

//        
//        
//        var row = 0
//        var column = 0
//        for cell in 0 ..< data.length {
//            elevationMatrix[row][column] = Int(elevation[cell].bigEndian)
//            //print(elevationMatrix[row][column])
//            column += 1
//            
//            if column >= Srtm3.MAX_SIZE {
//                column = 0
//                row += 1
//            }
//            
//            if row >= Srtm3.MAX_SIZE {
//                break
//            }
//        }

        
        return ElevationDataGrid(elevationData: elevationData, boundingBoxAreaExtent: griddedAxisOrientedBoundingBox, resolution: resolutioni)
    }
    
    
    
}
            iLon = iLon + 1.0
        }
        
        
        let elevationDataWidth:Int = HGTManager.latLonToIndex(griddedAxisOrientedBoundingBox.getUpperRight(), boundingBox: griddedAxisOrientedBoundingBox, resolution: resolutiond).1 - HGTManager.latLonToIndex(griddedAxisOrientedBoundingBox.getLowerLeft(), boundingBox: griddedAxisOrientedBoundingBox, resolution: resolutiond).1 + 1
        let elevationDataHeight:Int = HGTManager.latLonToIndex(griddedAxisOrientedBoundingBox.getUpperRight(), boundingBox: griddedAxisOrientedBoundingBox, resolution: resolutiond).0 - HGTManager.latLonToIndex(griddedAxisOrientedBoundingBox.getLowerLeft(), boundingBox: griddedAxisOrientedBoundingBox, resolution: resolutiond).0 + 1
        
        NSLog("elevationDataWidth \(elevationDataWidth)")
        NSLog("elevationDataHeight \(elevationDataHeight)")
        
        // this is the data structure that will contain the elevation data
        var elevationData:[[Int]] = [[Int]](count:elevationDataWidth, repeatedValue:[Int](count:elevationDataHeight, repeatedValue:Srtm.NO_DATA))
