View Full Version : Getting Lat and long area from user's selection

01-20-2004, 04:50 PM
I am using the mappoint ActiveX control in a VB app. I want to get a range of lat and long based on what area the user selects.

I can get the objMap.SelectedArea and I can check for pushpins, select pushpins etc but I can't get the lat and long of the selected area.

I can get the top, left, width, height of the selected area in relation to the active map but that is a far cry from getting the lat/long.

Does anyone know of a calculation I can use?


01-21-2004, 04:31 AM
Here's what I use to do that

Dim sa As MapPoint.SelectedArea
Dim dbllat As Double
Dim dbllon As Double
sa = objmap.SelectedArea

objloc = objmap.XYToLocation(sa.Left, sa.Top)
CalcPos(objmap, objloc, 1)
objloc = objmap.XYToLocation(sa.Left + sa.Width, sa.Top + sa.Height)
CalcPos(objmap, objloc, 2)

It gets the top left of the square, assigns it to a location object and then uses the code in the article below to obtain the long and lat, then does it again for the bottom right corner (got by taking the left and adding the width to it and the top and adding the height, I know in theory you should subtract the height from the top but heh it works!! :D )



02-18-2004, 09:27 AM
I'm using a AxMappoint.AxMappointControl in my VB.NET project, and I don't get the "SelectedArea" option on my control. How can I get the selected area from an ActiveX control?

02-19-2004, 10:40 AM
you won't get it as axmappointcontrol1.selectedarea, you have to declare a mappoint object, like objmap in my example above and its part of that



02-19-2004, 10:49 AM
Well, I already have an ActiveX control on my form, so declaring a new mappoint control dosen't really help. I have tried to declare a mappoint.mappoint control and assign it to my ActiveX control, but i get an "Invalid cast" error. So apperently I can't use that interface with the ActiveX control. So I'm wondering how to get the selected area then? Am I overlooking something?

02-23-2004, 08:55 AM
OK, now I'm back doing some coding work I'll show you exactly instead of from my note book :)

Dim objmap As MapPoint.Map

I normally dothat in the globals at the start, just in case :)

objmap = AxMappointControl1.ActiveMap

And thats in form.load

Once you've declared objmap as a mappoint object and assigned it to the active map of your control, selectedarea will be a control you can selet from it :D


02-23-2004, 01:28 PM
Just what I needed. Thanks.

02-23-2004, 01:30 PM
I don't know why I overlooked that one. Thanks for your help. I got it working now.

02-24-2004, 04:02 AM
:) no worries