I'm wondering if there's a way to get the longitude/latitude coordinates from the center of a data frame? The problem I'm faced with is this: I want to set a bookmark and have ArcMap tell me the coordinates of the center of that bookmark. (Without using a mouse. This all needs to be automated.)
This is akin to hovering one's mouse over the center of a map and reciting the long./lat. numbers that are shown at the bottom of the ArcMap window.
I'm pretty "green" when it comes to VBA programming in ArcMap 10.0. At first I thought I could utilize the "Info" tool, but now I'm guessing that I need to get the use the IEnvelope interface to calculate the center of the map, then grab the coordinates from that. Any ideas?
Best Answer
I would recommend using the IActiveView.Extent property. You can cast an IMap to an IActiveView and vice versa. http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//001200000199000000
The Extent property will return an IEnvelope that has an X and Y Max and Min that you can use to calculate the center if you would like.
http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//002m00000169000000
To get the IActiveView instance you can use the IApplication.Document property and cast the Document to an IMxDocument. You can then get an IActiveView using IMxDocument.ActiveView property. http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000054000000
Some code-
Here is a gis.stackexchange post that describes taking a map x,y and converting it to a lat, long. Extracting lat/long from screen when using British National Grid projection in ArcGIS Desktop?
In particular, follow these steps-