Last active
August 21, 2018 14:57
-
-
Save aclima93/f22f94a22a819e9923c21b8264d5cb26 to your computer and use it in GitHub Desktop.
ARKit & CoreLocation + Getting Nearby POIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var locationManager: CLLocationManager! | |
var latestLocation: CLLocation? | |
var pois: [PointOfInterest]! | |
func getPOIs() { | |
// formulate natural language query for nearby POIs | |
let request = MKLocalSearch.Request() | |
request.naturalLanguageQuery = "Restaurants" // or any other thing you might be interested in | |
request.region = MKCoordinateRegion(center: (latestLocation?.coordinate)!, | |
latitudinalMeters: 2000, | |
longitudinalMeters: 2000) | |
// getting POIs | |
let search = MKLocalSearch(request: request) | |
search.start { | |
(response, error) in | |
guard let response = response else { | |
if let error = error { | |
print("Search error: \(error)") | |
// TODO: handle error | |
} | |
return | |
} | |
// add POIs to AR scene | |
self.pois = [] | |
for item in response.mapItems { | |
let location = CLLocation(coordinate: item.placemark.coordinate, altitude: 0) | |
let distance = Int( round( self.latestLocation!.distance(from: location) )) | |
let title = "\(item.placemark.name!)\n\(distance) m" | |
let poi = PointOfInterest(title: title, | |
latitude: location.coordinate.latitude, | |
longitude: location.coordinate.longitude, | |
altitude: location.altitude) | |
self.pois.append(poi) | |
self.addPOIToARScene(poi) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment