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!