Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

How To Make An App Like Pokemon Go

In this tutorial, you'll learn how to make an app like Pokemon Go. You'll learn how to use augmented reality and location services to get gamers outdoors!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/725-how-to-make-an-app-like-pokemon-go

Awesome tutorial. I just bashed it out now and it looks are works great. Not used SceneKit before until now.

thanks pierredrks so much for this great tutorial! Your Demo runs on my device but cannot find the 3 red markers, though I replaced the location data in your Demo source code, which is near my own location.

And when I walk with my iPhone running your Demo, even though I pass the 3 places that quite near the location data, the video preview doesnot show. ( I know the 3 places that the location data represent.)
I also found that, after running your Demo, I cannot find your Demo App in " Private — Camera ".
Please help, thanks!

Hi sunlite,

i checked the final project and for me it works. Is it possible that you mixed latitude and longitude for your places?
The app will only be visible inside Private/Camera after it tried to access the camera.

It works :slight_smile: Sorry that I mixed the data before.

Hey @pierredrks. Awesome tutorial. One quick question, though I have not executed this tutorial myself, I would like to know what all the things to be considered If I want to show a real time rendering of a sub-surface materials(pipes/ cables etc) provided its GIS data? .
Am talking about something like this http://www.grintec.com/uploads/images/gallery/40/Augview-im-Einsatz-img001.jpg

Pic Source - Google

Hi pierredrks,
This is one of the best article which i have seen.
Informative and useful.

Thank you for sharing.

Hello Perredrks,

Really enjoyed the tutorial. Well written and have learned a lot.

Thanks,

Ron Cookson

Hello Perredrks, I want to get rid of hard-coded enemies, but donot want to use a back-end data provider firstly. I noticed your suggestion : " For example, you could create some random locations around your current position, use the PlacesLoader from our original Augmented Reality tutorial,". and I studied your original Augmented Reality tutorial link, but still cannot get a method to create some random locations around my current position, would you please be more specified on it?

thanks!

Hi. The app seems to have worked once and now I’m getting the errors below. Note ‘Unable to retrieve CarrierName’ and ‘unexpectedly found nil while unwrapping an optional value’

Latest version of Xcode and iPhone 6 running latest update.Help!!!

2017-03-04 14:57:36.802658 AR_Hunt[9912:3705558] [DYMTLInitPlatform] platform initialization successful
2017-03-04 14:57:37.025260 AR_Hunt[9912:3705476] Metal GPU Frame Capture Enabled
2017-03-04 14:57:37.026330 AR_Hunt[9912:3705476] Metal API Validation Enabled
2017-03-04 14:57:37.460738 AR_Hunt[9912:3705546] [LogMessageLogging] 6.1 Unable to retrieve CarrierName. CTError: domain-2, code-5, errStr:((os/kern) failure)
2017-03-04 14:57:52.869064 AR_Hunt[9912:3705476] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-03-04 14:57:52.875379 AR_Hunt[9912:3705476] [MC] Reading from public effective user settings.
fatal error: unexpectedly found nil while unwrapping an Optional value
2017-03-04 14:57:53.423061 AR_Hunt[9912:3705476] fatal error: unexpectedly found nil while unwrapping an Optional value
Thanks Ron

Also, forgot that the error above is from the final project with the following long lat changes:
func setupLocations() {
let firstTarget = ARItem(itemDescription: “Jake”, location: CLLocation(latitude: 34.4134, longitude: -118.4820), itemNode: nil)
//let firstTarget = ARItem(itemDescription: “Jake”, location: CLLocation(latitude: 34.1548, longitude: -118.6474, itemNode: nil)
targets.append(firstTarget)

let secondTarget = ARItem(itemDescription: "Corey", location: CLLocation(latitude: 34.4134, longitude: -118.4824), itemNode: nil)
//let secondTarget = ARItem(itemDescription: "Corey", location: CLLocation(latitude: 34.1548, longitude: -118.6476), itemNode: nil)
targets.append(secondTarget)

let thirdTarget = ARItem(itemDescription: "Justin", location: CLLocation(latitude: 34.4134, longitude: -118.4829), itemNode: nil)
//let thirdTarget = ARItem(itemDescription: "Justin", location: CLLocation(latitude: 34.1548, longitude: -118.6478, itemNode: nil)
targets.append(thirdTarget)

for item in targets {
  let annotation = MapAnnotation(location: item.location.coordinate, item: item)
  self.mapView.addAnnotation(annotation)
}

}

thanks,

Ron

@sunlite No problem i had the same a few weeks ago when i bought a new telescope. For your second question: Have a look at getDummyAnnotations in https://github.com/DanijelHuis/HDAugmentedReality/blob/master/HDAugmentedRealityDemo/ViewController.swift

@kmkxcoder Showing the pipes shouldn’t be too hard. Our SceneKit book may help you. The hard stuff is to take the inaccuracy of the position (GPS signal) into account. Here can an object detection algorithm help.

@ron_cookson This doesn’t seem to be related with the final project, it looks more like there is a settings problem. Can you add an exception breakpoint? Open the Breakpoint Navigator (cmd + 7) and click the + sign at the bottom and Exception Breakpoint... and run again. The execution should stop at the line that caused the exception.

Thanks for the quick response. Did what you said. The breakpoint line is in the MapViewController: extension MapViewController: MKMapViewDelegate

        self.present(viewController, animated: true, completion: nil)

Ron

Ok, then the next step is to add a breakpoint to this line and check if storyboard and /or viewController is nil. If viewController is nil, open the storyboard and select View Controller Scene in the Identity Inspector check if the Storyboard ID is the same as in the code

if let viewController = storyboard.instantiateViewController(withIdentifier: "ARViewController") as? ViewController {

thanks pierredrks so much!
When I use " locationManager.location?.coordinate.latitude " and " locationManager.location?.coordinate.longitude " to replace the hard coded " 45.554833 " and " 18.695433 " as follows, there are errors like : " fatal error: unexpectedly found nil while unwrapping an Optional value", please help, thanks!
override func viewDidLoad() {
super.viewDidLoad()

mapView.userTrackingMode = MKUserTrackingMode.followWithHeading

if CLLocationManager.authorizationStatus() == .notDetermined {
  locationManager.requestWhenInUseAuthorization()
  
  let lat = locationManager.location?.coordinate.latitude       //45.554833
  let lon = locationManager.location?.coordinate.longitude    //18.695433
  let delta = 0.05
  let count = 10
  let dummyAnnotations = getDummyAnnotations(centerLatitude: lat!, centerLongitude: lon!, delta: delta, count: count)
  ......

Pierredrks,

I am getting the same error as Sunlite above. I am using the final project download to test . This way the errors did not come from my retyping and adding code as I read the article.

Thanks,

Ron

@sunlite i guess that you call this stuff too early, at this time the location manager didn’t start. Use the didUpdateLocation delegate method and create the dummy annotations there.

Btw. your code would only work once, after the user granted permissions the code inside the if statement won’t be executed.

@ron_cookson what is the error you get?

How to lock the Wolf / Dragon’s X and Y axis. It is moving along with the camera instead of staying Z distance from the main camera

Hi pierredrks,
Shall I Create dummyAnnotation after the sentence " self.userLocation = userLocation.location " below?
Thanks !

extension MapViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
self.userLocation = userLocation.location
// To Create dummyAnnotation here
}

@pierredrks
Hi pierredrks,
Got an error in Swift running at this code: " getRanAnnotations ", stuck here for some days, please help, thanks !:
" extension MapViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { self.userLocation = userLocation.location
let lat = self.userLocation?.coordinate.latitude
let lon = self.userLocation?.coordinate.longitude
let ranAnnotations = getRanAnnotations(centerLatitude: lat!, centerLongitude: lon!)
"
fatal error: unexpectedly found nil while unwrapping an Optional value

libswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never:
0x100611184 <+0>: stp x26, x25, [sp, #-80]!
0x100611188 <+4>: stp x24, x23, [sp, #16]
0x10061118c <+8>: stp x22, x21, [sp, #32]
0x100611190 <+12>: stp x20, x19, [sp, #48]
0x100611194 <+16>: stp x29, x30, [sp, #64]
0x100611198 <+20>: add x29, sp, #64 ; =64
0x10061119c <+24>: mov x19, x6
0x1006111a0 <+28>: mov x20, x5
0x1006111a4 <+32>: mov x21, x4k
0x1006111a8 <+36>: mov x22, x3
0x1006111ac <+40>: mov x23, x2
0x1006111b0 <+44>: mov x24, x1
0x1006111b4 <+48>: mov x25, x0
0x1006111b8 <+52>: adr x8, #936936 ; protocol descriptor for Swift.CVarArg + 88
0x1006111bc <+56>: nop
0x1006111c0 <+60>: add x0, x8, #16 ; =16
0x1006111c4 <+64>: movz w1, #0x28
0x1006111c8 <+68>: orr w2, wzr, #0x7
0x1006111cc <+72>: bl 0x1006114b0 ; rt_swift_allocObject
0x1006111d0 <+76>: mov x8, x0
0x1006111d4 <+80>: stp x22, x21, [x8, #16]
0x1006111d8 <+84>: strb w20, [x8, #32]
0x1006111dc <+88>: str w19, [x8, #36]
0x1006111e0 <+92>: adr x3, #241008 ; partial apply forwarder for Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never).(closure #2)
0x1006111e4 <+96>: nop
0x1006111e8 <+100>: mov x0, x25
0x1006111ec <+104>: mov x1, x24
0x1006111f0 <+108>: mov x2, x23
0x1006111f4 <+112>: mov x4, x8
0x1006111f8 <+116>: bl 0x100504b80 ; function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <preserving fragile attribute, ()> of Swift.StaticString.withUTF8Buffer ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
-> 0x1006111fc <+120>: brk #0x1"