Created
May 28, 2016 07:23
-
-
Save RosaryMala/488ee6fb0246982ffa109afc4d3e3635 to your computer and use it in GitHub Desktop.
Functions to convert between WGS84 and bing mercator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Hello. Excuse me, can you say, what is
20037508.34
here?