Use cesium to get FVector location from GPS LAT/LNG/ALT

Hi all…

Does cesium have a utility type function that allows you to generate a cesium location (FVector) from a given latitude, longitude and height/altitude values?

I was thinking about using the Georeference object at runtime to set it’s location using the SetGeorferenceOriginLogitudeLatitudeHeight() to set it’s origin, then use the

  • Georeference->OriginLongitude
  • Georeference->OriginLatitude
  • Georeference->OriginHeight
    values to create an FVector from that…

But, that seems like a lot of overhead. Was hoping for more of an easier approach utility function.


The function you’re looking for is TransformLongitudeLatitudeHeightToUnreal. It’s available on the CesiumGeoreference.

Awesome! Thank you so much for your help!!!


Hi Kevin…

I finally got a place in my project today where I could start using the function you told me about…

These are the values I sent into

  • Latitude :44.9095
  • Longitude: -123.003
  • Altitude: 213

FVector myVec = cesium->CreateCesiumLocationVectorFromCoords(Longitude, Latitude, Altitude);

These are the values I got back.

{X=-31628.147232390009 Y=-82245.256571710110 Z=385.72559392452240}

Are those return values in the myVec accurate? Or am I doing something wrong?

I’m trying to put a debug sphere at the myVec location and I’m not seeing it anywhere.

It’s impossible for me to say with the information you’ve provided. You haven’t told me how you implemented CreateCesiumLocationVectorFromCoords, so I can’t check that for correctness. And you haven’t told me where your CesiumGeoreference is located, so it’s impossible to say if the coordinate value it has computed, which are relative to the georeference origin, are correct.

1 Like

Hi Kevin…

Really sorry about that, I cut and pasted the wrong bit of code…
As you can see here, my function is just a wrapper around the cesium function you told me about.

ACesiumUtility is a small AActor class I created to wrap some of the Cesium functionality. It has a pointer references to the geo reference, sunsky, and tileset. This class was turned into a Blueprint, dragged onto the scene and populated from the various cesium variables created through the Unreal Engine Cesium panel.

The function I posted above is from another class that uses the ACesiumUtility wrapper class, I am feeding in a real world GPS coordinate value that we have when I call this function.

// Take a real world location and convert it to a cesium location
FVector ACesiumUtility::CreateCesiumLocationVectorFromCoords(float Longitude, float latitude, float altitude)
       return CesiumGeoreference->TransformLongitudeLatitudeHeightToUnreal(FVector(Longitude, latitude, altitude));

I’d recommend using double instead of float for longitude / latitude / height. But otherwise that looks like it should work just fine.

I’m not sure where you’re getting your height values, but make sure they’re ellipsoidal heights, not geoid / mean sea level heights. The two can be tens of meters different, depending on where you are in the world.

Other than that, I’m not sure why your debug spheres aren’t showing up. You may have to share more of that code.

Hi Kevin,
The data we get is from a different source, they give us lat/lng/alt data in float format. Which is why I used float variables. There is really nothing I can do about that. However, I will make note of it for future reference in case I can influence some data type decisions down the road.

Oh and the reason the spheres were not showing up is because when trying to draw a debug sphere you need to supply a UWorldObject to the function… I was using GetWorld(). It was returning null for some reason, so I ended up using a different objects GetWorld() function. When I did that, my spheres started drawing correctly.


Learned a valuable lesson… Was having a lot of issues with my heights not being right. I forgot one important step… Convert feet to meters. My altitudes/heights were in feet, not meters, as soon as I made the feet to meter calculation on each FVector, my objects starting showing up in the right locations.