Hi, I am using V2.0 Desktop Edition in an old project & need to to know the GPS coordinates of the center of the Panned area.
I can get the Center of the control, but how do I convert it to GPS long/Lattitude?
MapSuite.DesktopEdition.Map mapControl ;
PointR r = mapControl.CurrentExtent.Centroid;
Please help
How to get the Location Coordinates of the center of the Map
Hi Arvind,
Please try the below codes:
map1.CurrentExtent = new RectangleR(-20037508.352, 20037508.352, 20037508.352, -20030000);
PointR r = map1.CurrentExtent.Centroid;
MapSuiteProjection.TransverseMercatorProj proj = new MapSuiteProjection.TransverseMercatorProj();
double longitude, latitude;
proj.ConvertTransverseMercatorToGeodetic(r.X, r.Y, out longitude, out latitude);
If the issue persists, don’t hesitate to let us know.
Johnny
Thanks for your response, however the code snippet does not seem to work.
I am getting 0.0 for the r.X & latitude for all values.
As mentioned we are displaying the MapSuite.DesktopEdition.Map & the user can zoom in/out, pan, drag map around. I want to get the GPS location of the center of the displayed map area.
Also what do the following numbers mean?
new RectangleR(-20037508.352, 20037508.352, 20037508.352, -20030000);
(FYI : I am using the MapSuiteCommon.dll & DesktopEdition.dll v 2.71.5.0)
Thanks
–Arvind
Hi Arvind,
Sorry the previous reply might make you confused. The new RectangleR(-20037508.352, 20037508.352, 20037508.352, -20030000) is means the whole world extent under spherical mecator projection system. but don’t care about it if your map control current extent have been assigned.
As for how to get the center point of map area, I think you can try to register the “CurrentExtentChanged” event to get the center point when zoom in/out,pan dynamically:
private void Form1_Load(object sender, EventArgs e)
{
Rectangle Rect = new Rectangle(0, 0, map1.Width, map1.Height);
map1.CanvasGeoBrush = new GeoLinearGradientBrush(Rect, GeoColor.GeographicColors.Ocean1, GeoColor.GeographicColors.Ocean2, GeoLinearGradientMode.ForwardDiagonal);
map1.CurrentExtentChanged += new MapSuite.DesktopEdition.Map.CurrentExtentChangedEventHandler(map1_CurrentExtentChanged);
Layer statesLayer = new Layer(@"…\Data\states.shp", true);
statesLayer.ZoomLevel01.GeoStyle = GeoAreaStyles.GetSimpleAreaStyle(GeoColor.KnownColors.Transparent, GeoColor.KnownColors.OliveDrab);
statesLayer.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.ZoomLevel18;
map1.Layers.Add(statesLayer);
map1.CurrentExtent = new RectangleR(-109, 37, -90, 24);
}
void map1_CurrentExtentChanged(RectangleR Extent, int MapWidth, int MapHeight, MapLengthUnits MapUnit)
{
PointR r = Extent.Centroid;
label3.Text = r.X.ToString();
label5.Text = r.Y.ToString();
}
Note: the codes sample is under EPSG 4326 projection(decimal degree), which is the same with GPS location. If your projection is under spherical mecator, then we need to do a projection conversion like:
PointR r = Extent.Centroid;
MapSuiteProjection.TransverseMercatorProj proj = new MapSuiteProjection.TransverseMercatorProj();
double longitude, latitude;
proj.ConvertTransverseMercatorToGeodetic(r.X, r.Y, out longitude, out latitude);
If there is anything confused, please feel free to let us know.
Regards,
Johnny
Johnny,
Thanks a lot. That seems to work as expected.
Arvind
Hi Arvind,
Good to hear it works.
Any questions, don’t hesitate to let us know.
Regards,
Johnny