ywologist2
ywologist2

Reputation: 15

How to convert correct coordinates for Cesium?

I have the following coordinates:103.84958233542338,1.3669641300494784

I cannot tell if it's in the correct coordinates format for Cesium. It gives me a developer error "Cartesian is required." I have the following codes too.

  var storecoord=[103.84958233542338,1.3669641300494784];
  var splitcoord = storecoord.split(',');
  var pos = Cesium.Cartesian3.fromDegrees(splitcoord[0],splitcoord[1]);
  var carto  = Cesium.Ellipsoid.WGS84.cartesianToCartographic(pos);
  var lon = Cesium.Math.toDegrees(carto.longitude);
  var lat = Cesium.Math.toDegrees(carto.latitude);

Any idea on any part that when wrong. I would like to use the variable lon & lat to create billboard.

Upvotes: 1

Views: 2805

Answers (1)

emackey
emackey

Reputation: 12383

Make sure you've specified lon, lat in the correct order for fromDegrees.

Also, you can't call .split on an array, it's already split. And it looks like you're converting from lon/lat to Cartesian3 and then back to lon/lat, is that just to verify the round-trip?

Anyway here's a Sandcastle demo with a billboard at your lon/lat location:

var storecoord=[103.84958233542338,1.3669641300494784];

var viewer = new Cesium.Viewer("cesiumContainer");

var lon = storecoord[0];
var lat = storecoord[1];

viewer.entities.add({
  position: Cesium.Cartesian3.fromDegrees(lon, lat),
  billboard: {
    image: "../images/Cesium_Logo_overlay.png",
  },
});

viewer.zoomTo(viewer.entities);

Upvotes: 1

Related Questions