# Convert (Longitude, Latitude) to (X, Y) on a map

// Get the latitude as a value between 0 and 180,
// where the negative values represent values South of the Equator
double latitude = lat + 90.0;
// Get the longitude as a value between 0 and 360,
// where the negative values represent values West of the Greenwich Meridian.
double longitude = lon + 180.0;

// calculate how many pixels are needed to represent each degree for width and height
double pixelsWidth = map.Width/360.0;
double pixelsHeight = map.Height/180.0;

// Calculate how many pixels we need to represent our latitude value
double latitudePixels = latitude * pixelsHeight;
// Calculate how many pixels we need to represent our longitude value
double longitudePixels = longitude * pixelsWidth;

// The X coordinate of our point is the longitudePixels value
float x = (float)longitudePixels;
// The Y coordinate of our point is 180-latitude
// since the Y axis is facing down but the map is facing up
float y = (float) ((180.0 * pixelsHeight) – latitudePixels);