Select to view content in your preferred language

LocationToScreen result is absurd...

814
3
Jump to solution
11-07-2018 03:52 AM
GarGueg
New Contributor

Hi ! 
I'm using the method LocationToScreen (I'm in .NET) to place icons on my map but the result I have with it is absurd... Like a point with -70000, 10000. 

I don't get why because I use ScreenToLocation to get geographic coordinates with success.

Here is the method with LocationToScreen inside : 

public void GetMapPointCoordinates()
{
var targetLatitude = ConvertDMSToDD(DisplayedTargetLatitude);
var targetLongitude = ConvertDMSToDD(DisplayedTargetLongitude);
MapPoint mapPoint = new MapPoint(targetLatitude, targetLongitude, ViewRadarMap.MapFranceOffLine.Map.SpatialReference);
Point pt = ViewRadarMap.MapFranceOffLine.LocationToScreen(mapPoint);
double marginBottom = ViewRadarMap.ActualHeight - pt.Y;
double marginRight = ViewRadarMap.ActualWidth - pt.X;
_iconPosition.Bottom = marginBottom - 40;
_iconPosition.Right = marginRight - 40;
_iconPosition.Top = pt.Y - 40;
_iconPosition.Left = pt.X - 40;
ViewRadarMap.TargetPositionIcon.Margin = IconPosition;
ViewRadarMap.IconNeutral.Margin = IconPosition;

}

I tried to change the SpatialReferences but the result is still absurd...
Help me pleeeeaaase !

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Notable Contributor

Is your map's spatial reference longitude/latitude? (from the result I'm guessing no) Try changing the MapPoint definition to this instead, so that your coordinates you use matches the spatial reference:

MapPoint mapPoint = new MapPoint(targetLongitude, targetLatitude, SpatialReferences.Wgs84);

Also note I swapped the long/lat order

View solution in original post

3 Replies
dotMorten_esri
Esri Notable Contributor

Is your map's spatial reference longitude/latitude? (from the result I'm guessing no) Try changing the MapPoint definition to this instead, so that your coordinates you use matches the spatial reference:

MapPoint mapPoint = new MapPoint(targetLongitude, targetLatitude, SpatialReferences.Wgs84);

Also note I swapped the long/lat order

GarGueg
New Contributor

I don't know what kind of black magic this is but... It worked. 
Thank you so much ! 

Can you explain me (shortly) why these changes were mandatory in order to get things right ? 

0 Kudos
dotMorten_esri
Esri Notable Contributor

You are creating a point using Longitude and Latitude, so you need to specify the correct "units" using that spatial reference. WGS84 is one spatial reference that uses Longitudes and Latitudes in degrees.

Most likely your map isn't using long/lat values but a projection - probably WebMercator which uses Meters instead. So basically you were providing a location a few meters of (0,0) which just off the coast of Africa, which was several thousand pixels away from your current location, thus giving you some very absurd looking screen coordinates.

It's sort of like paying for a $10 item, but you pay with 10pesos - basically units getting mixed up.

Second all MapPoint objects are defined as X,Y which roughly translates to Long,Lat, so the order you had was "backwards". 

0 Kudos