1

I'm currently working on a project where I need the user to tell where (on the real world map) to build a wall.

Question: What (in your opinion) is the most accurate way for the user to show(/tell) where to place the wall?

Idea 1 I have thought about drawing on a map, But that wouldn't be so accurate.

Idea 2 Another thing that I have thought of is, that the user should place their phone on the beginning and the end of the wall. And in that way the app could use CLLocationManager to print the locations on the map, and also measure the distance between the two ends.

This is the code that I tried my thought with, but it wasn't really that accurate at all.

let locationManager = CLLocationManager()

var location1: CLLocation = CLLocation()
var location2: CLLocation = CLLocation()

override func viewDidLoad() {
    super.viewDidLoad()
    setup()
}

func setup() {
        resett.isHidden = true

        // Ask for Authorisation from the User.
        self.locationManager.requestAlwaysAuthorization()

        // For use in foreground
        self.locationManager.requestWhenInUseAuthorization()

        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
            locationManager.activityType = .fitness
            locationManager.startUpdatingLocation()
        }
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        currentCord.text = "\(locValue.latitude) \(locValue.longitude)"
    }

    func measure(cord1: CLLocation, cord2: CLLocation) -> Float {
        let distanceInMeters = cord1.distance(from: cord2) //result is in meters
        return Float(distanceInMeters)
    }

    func calculateCoordinates(status: Int) {
        let coordinate = calculate()

        if status == 1 {
            location2 = coordinate

            let measured = measure(cord1: location1, cord2: location2)
            print("\(measured) m")
            displayLabel.text = "\(measured)m"
            resett.isHidden = false
        } else {
            location1 = coordinate
        }
    }

    func calculate() -> CLLocation {
        let locValue:CLLocationCoordinate2D = locationManager.location!.coordinate
        let coordinate = CLLocation(latitude: locValue.latitude, longitude: locValue.longitude)

        return coordinate
    }

    @IBAction func FirstAction(_ sender: Any) {
        button1.setTitle("Klar", for: .normal)
        calculateCoordinates(status: 0)
    }

    @IBAction func SecondAction(_ sender: Any) {
        button2.setTitle("Klar", for: .normal)
        calculateCoordinates(status: 1)
    }

Thanks in advance!

J. Doe
  • 81
  • 12
  • 1
    You need to give more information and be more clear, what is the specific problem you are facing? CLLocationManager, "measure a distance" and "drawing on a map" are not really related – jalone Jun 16 '17 at 12:42
  • 1
    Sorry, have updated the question now. – J. Doe Jun 16 '17 at 12:44

2 Answers2

0

Assuming you mean a real-world "wall", with order of dimension of centimeters to a few meters, the location of the iPhone GPS is really not adapt for these kind of measurments, being the typical minimum error on good covered areas 5 meters.

If asking explicitely the geocoordinates (with very high accuracy) is not feasable: I'd rather ask the user explicitly the dimensions and then maybe dragging the object (wall) on the map, zooming as much as possible while approaching the possible final position.

PS: there are anyway many optimizations that are possible to be made to increase the accuracy of the CLLocationManager, first of all filtering away results with low accuracy and manually away the one with big horizzontal accuracy issues after receiving it.

jalone
  • 1,953
  • 4
  • 27
  • 46
  • Do you think it would be possible to first ask the user for the dimensions then using ARKit to place the wall on the map? – J. Doe Jun 16 '17 at 13:12
  • Yes, i am pretty sure that should not be a problem, given you have some solid AR basis :) the user should be able to drag/move/command the wall and it would be rendered accordingly to the perspective. You can eventually use the location to approximate the initial location of the wall and then have the user refine it if this is what you need. – jalone Jun 16 '17 at 13:15
  • 1
    I will try to do a demo of that then. I will see if I can post the github link here when I'm done – J. Doe Jun 16 '17 at 13:19
0

The unfortunate answer is that the GPS on an iPhone is not very accurate. If you can get a location accurate within a 32 meter radius circle, you're doing well, and that's in an open area with clear line of sight to the sky, and no radio interference. If things are less ideal, the results can be far less accurate.

(Apple reports a "horizontal accuracy" reading in it's GPS location results that is actually a radius for the margin of error.)

For the purposes of building a wall, 32 meters is simply not good enough, and the GPS in an iPhone can't reliably do better. You really need surveying equipment for that.

Duncan C
  • 128,072
  • 22
  • 173
  • 272