private Point FromLatLngToPoint(LatLng latLng) { double x = this.pixelOrigin.X + latLng.Lng * this.pixelsPerLngDegree; // NOTE(appleton): Truncating to 0.9999 effectively limits latitude to // 89.189. This is about a third of a tile past the edge of the world tile. var sinY = this.Bound(Math.Sin(this.DegreesToRadians(latLng.Lat)), -0.9999, 0.9999); double y = this.pixelOrigin.Y + 0.5 * Math.Log((1 + sinY) / (1 - sinY)) * -this.pixelsPerLngRadian; return new Point(x, y); }
public Bounds GetCorners(LatLng center, int zoom, int width, int height) { var scale = Math.Pow(2, zoom); var centerPoint = this.FromLatLngToPoint(center); var southWestPoint = new Point(centerPoint.X - (width / 2) / scale, centerPoint.Y + (height / 2) / scale); var southWestLatLng = this.FromPointToLatLng(southWestPoint); var northEastPoint = new Point(centerPoint.X + (width / 2) / scale, centerPoint.Y - (height / 2) / scale); var northEastLatLng = this.FromPointToLatLng(northEastPoint); return new Bounds { NorthEast = northEastLatLng, SouthWest = southWestLatLng }; }