World Map Calculator

intermediate tasks

World Map Globe Edition · Common Tasks

This component is useful to:

  1. Convert units from one coordinate system to another (for instance from plane coordinates to degrees and vice-versa).

  2. Calculate the distance between cities.

You may also use this component to capture the current cursor coordinates and convert them to other coordinate system.

You may enable this component in two ways:

  • From the Editor, clicking on the “Open Calculator” button at the bottom of the World Map Globe inspector.

  • From code, using any of its API through map.calc accessor. The first time you use its API, it will automatically add the component to the globe gameObject.

On the Inspector you will see the following custom editor:

Converting coordinates from code

The Conversion static class provides methods that you can use directly without having an instance of the globe in the scene. For example, you can use: Conversion.GetLatLonFromSpherePoint (spherePosition, out latitude, out longitude) to obtain the latitude and longitude from a local sphere position.

Vector2 GetUVFromLatLon(float lat, float lon)

Returns the texture coordinates (UV) of a latitude/longitude assuming the texture fills the entire globe.

Vector2 GetLatLonFromUV(Vector2 uv)

Returns the latitude/longitude from a UV coordinate.

Vector2 GetUVFromSpherePoint(Vector3 p)

Returns the texture coordinates (UV) from a point on the globe sphere.

Vector3 GetSpherePointFromLatLon(double lat, double lon, double altitude = 0)

Vector3 GetSpherePointFromLatLon(float lat, float lon, float altitude = 0f)

Vector3 GetSpherePointFromLatLon(Vector2 latLon, float altitude = 0)

Returns the sphere local position from a latitude/longitude and optional altitude.

GetLatLonFromSpherePoint(Vector3 p, out double lat, out double lon)

GetLatLonFromSpherePoint(Vector3 p, out float lat, out float lon)

GetLatLonFromSpherePoint(Vector3 p, out Vector2 latLon)

Vector2 GetLatLonFromSpherePoint(Vector3 p)

Returns the latitude/longitude from a local sphere position

float Distance(Vector3 position1, Vector3 position2)

float Distance(float latDec1, float lonDec1, float latDec2, float lonDec2)

Returns the distance in meters from two positions.

GetTileFromLatLon(int zoomLevel, float lat, float lon, out int xtile, out int ytile)

Returns the x/y indices of a tile from a zoom level, latitude and longitude.

Vector2 GetLatLonFromTile(float x, float y, int zoomLevel)

Returns the latitude/longitude of a tile.

map.transform.TransformPoint(spherePosition)

Converts a sphere position (local space) to world space.

map.transform.InverseTransformPoint(worldPosition)

Converts a world space position into a sphere position.

Was this page helpful?