Skip to content

Instantly share code, notes, and snippets.

@RosaryMala
Created May 28, 2016 07:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RosaryMala/488ee6fb0246982ffa109afc4d3e3635 to your computer and use it in GitHub Desktop.
Save RosaryMala/488ee6fb0246982ffa109afc4d3e3635 to your computer and use it in GitHub Desktop.
Functions to convert between WGS84 and bing mercator
using System;
public class BingConvert
{
public static double[] WGS84toGoogleBing(double lon, double lat)
{
double x = lon * 20037508.34 / 180;
double y = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
y = y * 20037508.34 / 180;
return new double[] { x, y };
}
public static double[] GoogleBingtoWGS84Mercator(double x, double y)
{
double lon = (x / 20037508.34) * 180;
double lat = (y / 20037508.34) * 180;
lat = 180 / Math.PI * (2 * Math.Atan(Math.Exp(lat * Math.PI / 180)) - Math.PI / 2);
return new double[] { lon, lat };
}
}
@InsanusMokrassar
Copy link

Hello. Excuse me, can you say, what is 20037508.34 here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment