Transform latitude and longitude value to pixel value and vice-versa
19 Oct 20222 minutes to read
SfMaps offers two utility methods to transform the pixel values to longitude and latitude values and vice-versa. This method is used for both ShapeFileLayer and ImageryLayer.
-
GeopointToViewPoint(double latitude, double longitude)
- Converts the latitude and longitude values to screen point. Here, pass the parameters as latitude and longitude values, from that values we can get screen points x and y. -
GetLatLonFromPoint(Point point)
- Converts the screen point to longitude and latitude values. Here, pass the parameters as screen points x and y, from that points we can get longitude(Point.X) and latitude(Point.Y) values.
<maps:SfMaps x:Name="sfmap" >
<maps:SfMaps.Layers>
<maps:ShapeFileLayer x:Name="layer" Uri="world-map.shp">
<maps:ShapeFileLayer.Markers>
<maps:MapMarker x:Name="marker"
....
/>
</maps:ShapeFileLayer.Markers>
</maps:ShapeFileLayer>
</maps:SfMaps.Layers>
</maps:SfMaps>
Point pixelPoint = layer.GeopointToViewPoint(21.00, 78.00);
Point longitudeLatitude = layer.GetLatLonFromPoint(pixelPoint);
marker.Latitude = longitudeLatitude.Y.ToString();
marker.Longitude = longitudeLatitude.X.ToString();