Select to view content in your preferred language

Getting Elevation completion handlers results none

474
1
Jump to solution
03-01-2022 09:32 PM
VinceCarloSantos
New Contributor

Hi Ive been trying to get an elevation based on a point. here is my code, but the get elevation part dont respond to the completion handler

 

let surface = AGSSurface()
                // Create an elevation source.
                let elevationURL = URL(string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")
                let elevationSource = AGSArcGISTiledElevationSource(url: elevationURL!)
                surface.elevationSources.append(elevationSource)
                elevationSource.load { error in
                    if error == nil {
                        // Add the elevation source to the surface.
                        surface.elevation(for: hasCurrentPoint) { elevation, error in
                            print("vince!!!")
                        }
                    }
                }

 

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Hi @VinceCarloSantos,

I'm betting that the AGSSurface() is deallocated before the completion block is called. Just set up an instance level variable to hold on to the surface.

Incidentally, you don't need to explicitly call load(). When you call any asynchronous method on a loadable object, we'll automatically load it if it isn't already loaded. That can help to make your code a little cleaner.

You can start to avoid these sorts of issues by adopting Swift Concurrency. You can read more about that in this blog post.

Hope that helps!

Nick.

View solution in original post

0 Kudos
1 Reply
Nicholas-Furness
Esri Regular Contributor

Hi @VinceCarloSantos,

I'm betting that the AGSSurface() is deallocated before the completion block is called. Just set up an instance level variable to hold on to the surface.

Incidentally, you don't need to explicitly call load(). When you call any asynchronous method on a loadable object, we'll automatically load it if it isn't already loaded. That can help to make your code a little cleaner.

You can start to avoid these sorts of issues by adopting Swift Concurrency. You can read more about that in this blog post.

Hope that helps!

Nick.

0 Kudos