2017-08-16 1 views
0

Comment puis-je obtenir le Lat/Lon d'un pixel dans une tuile spécifique dans google maps.Obtenez lat/lon de pixel avec la mosaïque dans google maps dans C#

par exemple - j'ai zoom 5, x = 4, y = 5.

Je veux obtenir le Lat/Lon de chaque pixel dans la matrice 256 X 256 de cette tuile

est là Un paquet ou une formule pour l'obtenir?

+0

https://developers.google.com/maps/documentation/javascript/examples/map-coordinates – scaisEdge

+0

Vous pourriez Dites-nous pourquoi vous avez besoin de la coord pour chaque pixel .. quand vous pouvez obtenir les coordonnées pour chaque position dinamically ??? – scaisEdge

+0

Je reçois une matrice flottante de 256 x 256 de données pour le zoom 5, x = 4, y = 5, et je dois obtenir le Lat/Lon de chaque valeur dans la matrice – asaf

Répondre

0

ici est la réponse en C#

la réponse a été prise de https://help.openstreetmap.org/questions/747/given-a-latlon-how-do-i-find-the-precise-position-on-the-tile

static void PixelXYToLatLongOSM(int pixelX, int pixelY, int zoomLevel, out float latitude, out float longitude) 
    { 
     int mapSize = (int)Math.Pow(2, zoomLevel) * 256; 
     int tileX = (int)Math.Truncate((decimal)(pixelX/256)); 
     int tileY = (int)Math.Truncate((decimal)pixelY/256); 

     float n = (float)Math.PI - ((2.0f * (float)Math.PI * (ClipByRange(pixelY, mapSize - 1)/256))/(float)Math.Pow(2.0, zoomLevel)); 

     longitude = ((ClipByRange(pixelX, mapSize - 1)/256)/(float)Math.Pow(2.0, zoomLevel) * 360.0f) - 180.0f; 
     latitude = (180.0f/(float)Math.PI * (float)Math.Atan(Math.Sinh(n))); 
    } 

    static float ClipByRange(float n, float range) 
    { 
     return n % range; 
    } 

    static float Clip(float n, float minValue, float maxValue) 
    { 
     return Math.Min(Math.Max(n, minValue), maxValue); 
    } 

    static void LatLongToPixelXYOSM(float latitude, float longitude, int zoomLevel, out int pixelX, out int pixelY) 
    { 
     float MinLatitude = -85.05112878f; 
     float MaxLatitude = 85.05112878f; 
     float MinLongitude = -180; 
     float MaxLongitude = 180; 
     float mapSize = (float)Math.Pow(2, zoomLevel) * 256; 

     latitude = Clip(latitude, MinLatitude, MaxLatitude); 
     longitude = Clip(longitude, MinLongitude, MaxLongitude); 

     float X = (float)((longitude + 180.0f)/360.0f * (float)(1 << zoomLevel)); 
     float Y = (float)((1.0 - Math.Log(Math.Tan(latitude * (Math.PI/180.0)) + 1.0/Math.Cos(latitude * (Math.PI/180.0)))/Math.PI)/2.0 * (1 << zoomLevel)); 

     int tilex = (int)(Math.Truncate(X)); 
     int tiley = (int)(Math.Truncate(Y)); 
     pixelX = (int)ClipByRange((tilex * 256) + ((X - tilex) * 256), mapSize - 1); 
     pixelY = (int)ClipByRange((tiley * 256) + ((Y - tiley) * 256), mapSize - 1); 
    }