To go step by step:
- How to use the new Geocode Blueprint function (or C++ API) in Cesium v2.16.0?
You’ll want a setup like this:
You can call the “Query Cesium ion Geocoder” node from your UI, maybe when a button is pressed, or as the user is typing, or something like that. The parameters are as follows:
Ion Access Token
- the token you use to access Cesium ion. If you leave this empty, it will use your project’s default token (the same token you use to load tiles from ion). Check the ion tokens page to make sure this token has access to the geocode
scope!
Cesium Ion Server
- this is the object containing information on the Cesium ion server to connect to. If unspecified, your project’s default server will be used. You would probably only change this if you’re using Cesium ion Self-Hosted or something like that where you need to be able to specify a different URL for Cesium ion.
Provider Type
- Cesium ion calls out to the Google or Bing geocoding services on the backend to actually perform the query. If you’re going to be using this geocoding query with Google data (like Google Photorealistic 3D Tiles), you should use the Google geocoder. If you’re using it with Bing data (like the Bing Maps raster overlays), you should use the Bing geocoder. If you aren’t using either of these, you can pick whichever you prefer or pick “Default” if you don’t care.
Request Type
- This can be either Search
or Autocomplete
. Autocomplete
should be used when you’re making queries as the user is typing - for example, the way Google Maps displays the list of results as you’re still typing in the address you’re looking for. Search
should be used when the user completes their query - clicks the search button, presses enter, that sort of thing.
Query
- this is the actual query string you obtained from the user. It’s whatever the user wants to search.
The “Query Cesium ion Geocoder” node is an asynchronous operation - it runs in the background while your code does other things. The first white exec pin off the node will run immediately after the query is sent, and the second white exec pin - the one marked On Geocode Request Complete
- will run when the query finishes. When this second pin runs, the remaining pins will be set. Success
will be true
if the geocoding completed successfully or false
if it failed. If the request failed, Error
will be an error string with information on why the request failed. If it succeeded, Result
will be a CesiumGeocoderServiceResult
object. A CesiumGeocoderServiceResult
object contains two fields - Attributions
, which is a list of credits you should show on screen (you can put this into a RichTextBlock on your UI), and Features
, which is an array of the locations found by the query. Which brings us to…
- How to extract coordinates (longitude, latitude, height) from the geocoder response?
This is pretty simple - just loop through the results (or some other way of getting elements from an array) and break the CesiumGeocoderServiceFeature
structs the array contains:
The
Display Name
property is what you should show to users - for example, for my query “philadelphia,” the first result has the display name “Philadelphia, PA, USA.”
The Longitude Latitude Height
and Globe Rectangle
properties contain the actual location information. There’s a bit of subtlety here - some geocoding results return areas (like if you search up “Manhattan,” you might get back the box that includes Manhattan instead of just a point in Manhattan), while others just return positions. For ease of use, we paper over the difference - if you ask for a Longitude Latitude Height
and the geocoding query returned a box, we will give you back the center of the box. If you ask for a Globe Rectangle
and the geocoding query returned a point, we give you a “box” where all corners are set to that point we got back.
In short: to extract the coordinates, just use the Longitude Latitude Height
pin on “Break Cesium Geocoder Service Feature.”
- How to smoothly move or fly the camera to that new location using Cesium’s
FlyTo
function?
This one is even simpler - just get your hands on a reference to the DynamicPawn you’re using and call “Fly to Location Longitude Latitude Height” on it:
- Is there a way to do this all in C++ instead of Blueprints (for performance & flexibility)?
Yes! Just take a look at how the Blueprint node is implemented.
- Any tips for binding this to a UI search bar input?
I don’t think there’s anything special here beyond how you would regularly add Blueprint nodes to a UI. Just try to find some way to handle the fact that georeference queries are async - for example, you could have a “QueryRunning” boolean that you set to true
using the first exec pin off of the “Query Cesium ion Geocoder” node, and then set to false
in the On Geocode Request Complete
exec pin. You can then set up your blueprint to only run geocoding queries when QueryRunning
is false
, so that you don’t end up running multiple queries before the first one has completed. You could also add some kind of loading indicator using this boolean.
Hope this helps!