![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
||||
|
||||
![]() Помогите перевести код С# на Delphi!
class gmaps { ... public Point tile(double lat, double lng, int zoom) { return new System.Drawing.Point(Xpixel(lng, zoom) / 256, Ypixel(lat, zoom)); } public int Xpixel(double lng, int zoom) { // Instead of -180 to +180, we want 0 to 360 double dlng = this.lng.Value + 180.0; // 256 = tile Width double dxpixel = dlng / 360.0 * 256 * Math.Pow(2, 17 - zoom); int xpixel = Convert.ToInt32(Math.Floor(dxpixel)); return xpixel; } public int Ypixel(double lat, int zoom) { // The 25 comes from 17 + (256=>2^8=>8) 17+8 = 25 // ypixelcenter = the middle y pixel (the equator) at this zoom level double ypixelcenter = Math.Pow(2, 25 - zoom - 1); // PI/360 == degrees -> radians // The trig functions are done with radians double dypixel = ypixelcenter - Math.Log(Math.Tan(lat * Math.PI / 360 + Math.PI / 4)) * ypixelcenter / Math.PI; int ypixel = Convert.ToInt32(Math.Floor(dypixel)); return ypixel; } ... } |
#2
|
|||
|
|||
![]() Как-то так:
Код:
unit Unit2; interface uses SysUtils, Windows, Classes, Math; type gmaps = class public function tile(lat, lng : Double; zoom : Integer) : TPoint; function Xpixel(lng : Double; zoom : Integer) : Integer; function Ypixel(lat : Double; zoom : Integer) : Integer; end; implementation { gmaps } function gmaps.tile(lat, lng: Double; zoom: Integer): TPoint; begin Result.X := Round(Xpixel(lng, zoom) / 256); Result.Y := Round(Ypixel(lat, zoom)); end; function gmaps.Xpixel(lng: Double; zoom: Integer): Integer; var dlng : Double; dxpixel : Double; begin dlng := lng + 180; // this.lng.Value + 180.0; <- не понятно, что за this.lng.Value dxpixel := dlng / 360.0 * 256 * Power(2, 17 - zoom); Result := Round(dxpixel); end; function gmaps.Ypixel(lat: Double; zoom: Integer): Integer; var ypixelcenter : Double; dypixel : Double; begin ypixelcenter := Power(2, 25 - zoom - 1); dypixel := ypixelcenter - Ln(Tan(lat * PI / 360 + PI / 4)) * ypixelcenter / PI; Result := Round(dypixel); end; end. |
#3
|
||||
|
||||
![]() Спасибо за помощь!
|