View Full Version : Latitude longitude from point on map

Sean M Westcott
01-20-2012, 05:16 PM
I am trying to get Latitude and longitude from a place I have highlighted on the map
this is what I have

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadLatLongToForm1.Click Dim objMap As MapPoint.Map
Dim objPoint As MapPoint.Location
objMap = objApp.ActiveMap

objApp.Visible = True
objApp.UserControl = True
Dim X As Long
Dim Y As Long
Dim dblLat As Double
Dim dblLon As Double

objPoint = objMap.XYToLocation(X, Y)
dblLat = objPoint.Location.Latitude
dblLon = objPoint.Location.Longitude

LatTxBox.Text = dblLat
LonTxBox.Text = dblLon

End Sub

this returns the center of the map not what I want


Sean M Westcott
01-30-2012, 08:23 AM
OK it looks like it might not be returning the center of the map when I mouse over the location I get 38.78450 and 77.20185 but the values for dbLat and dbLon are 38.7865098472685 and -77.2050159238279 do I need to round the numbers or something thanks

Mattys Consulting
01-31-2012, 06:55 AM
Hi Sean,

I'm fairly certain that you need to use the value from [e as system.eventargs].
ie; .XYToLocation(e.x, e.y);

Sean M Westcott
01-31-2012, 01:33 PM
Thanks so much I was doing it wrong this is what I ended up with

Private Sub AxMappointControl1_MouseDownEvent(sender As System.Object, e As AxMapPoint._IMappointCtrlEvents_MouseDownEvent) Handles AxMappointControl1.MouseDownEvent
Dim objLoc As MapPoint.Location
Dim dblLat As Double
Dim dblLon As Double
objLoc = AxMappointControl1.ActiveMap.XYToLocation(e.x, e.y)
dblLat = objLoc.Latitude
dblLon = objLoc.Longitude

LatTextBox.Text = dblLat
LonTextBox.Text = dblLon
End Sub

02-01-2012, 08:27 AM
And re. your rounding question: Round as appropriate for your text box, but don't round too much :-)

As a very rough guide, the Earth's circumference is about 40,000 km (yes it depends where you measure it), so 1 degree of latitude is about 111km (again, this varies according to latitude). Longitude varies even more - from about 111km (equator) to 0km (poles).

So an error of 1e-5 rounding is about 1metre of latitude; and 1metre of longitude at the equator. This is about the level of rounding usually used and is able to capture the accuracy of consumer GPS (20m typical; 6m under ideal conditions).