Skip to content

Instantly share code, notes, and snippets.

@csukuangfj
Forked from RosaryMala/BingConvert.cs
Created July 28, 2018 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csukuangfj/60c639fdc13411912e97c371865cbfc8 to your computer and use it in GitHub Desktop.
Save csukuangfj/60c639fdc13411912e97c371865cbfc8 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 };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment