Mappoint Methods question

George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Mappoint Methods question

Post by George »

Forum,

I am trying to use ActiveX with Mappoint. I found the following code in this forum
FUNCTION MapPointTest()
   local hToolBar, hStandard, oMapPoint, nDist
   oActiveX = TActiveX():New( oWnd, "MapPoint.Control.16" )
   oWnd:oClient = oActiveX // To fill the entire window surface

   oActiveX:Do( "Newmap", 1 )
   hToolBar = oActiveX:;GetProp( "Toolbars" )
   hStandard = OleGetProperty( hToolBar, "Item", "Standard" )
   OleSetProperty( hStandard, "Visible", .T. )
    oActiveX:GetProp( "Toolbars" )

   // The following code generate error
   oActiveX:Distance('205 Broadway, Lawrence, MA', '77 Centre Street, Boston, MA' )[/code] 
Error description: Error BASE/1004 Message not found: TACTIVEX:DISTANCE

From Mappoint Method help (Microsoft Developer Network)

Code: Select all | Expand

Applies to
Objects:   Map

Syntax
object.Distance(StartLocation, EndLocation)

Parameters
Part Description
object Required. An expression that returns a Map object.
StartLocation Required Location object. The start point of the distance to be measured.
EndLocation Required Location object. The end point of the distance to be measured.
I am using FWH 9.06 + xHarbour Sep 08 and a Mappoint trial version.

Any clue why ActiveX does not recognize the Distance method?

Regards,

George
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Mappoint Methods question

Post by James Bott »

George,

I have no experience with MapPoint but this:

"StartLocation Required Location object."

Might be indicating that the startLocation needs to be an object not a string. It is hard to tell from the description given.

Is there a method to return a location object from a string?

James
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Mappoint Methods question

Post by lailton.webmaster »

oActiveX:Do("Distance","205 Broadway, Lawrence, MA", "77 Centre Street, Boston, MA")

try it.

:lol:
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: Mappoint Methods question

Post by George »

James, Laiton
Thanks for responding my question.

Laiton,
If I use oActiveX:Do("Distance","205 Broadway, Lawrence, MA", "77 Centre Street, Boston, MA")
I get the same error message as before.

James,
This this the info from Microsoft developer network:
//------------------------------------------------------------------------------------------
Distance method
Returns the distance between two locations, in GeoUnits (miles or kilometers) as Double.

Applies to
Objects: Map

Syntax
object.Distance(StartLocation, EndLocation)

Parameters
Part Description
object Required. An expression that returns a Map object.
StartLocation Required Location object. The start point of the distance to be measured.
EndLocation Required Location object. The end point of the distance to be measured.

Remarks
To return the distance to a location, route, or route segment from another location, use the DistanceTo method on a Directions collection or Direction or Location object.

To return or set GeoUnits, use the Units property of an Application or MappointControl object.

Example
[Microsoft Visual Basic 6.0]
Sub ShowDistanceNYToLA()
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLocNY As MapPoint.Location
Dim objLocLA As MapPoint.Location
Dim objCenter As MapPoint.Location
Dim objTextbox As MapPoint.Shape
'Set up application and create Location objects
Let objApp.Visible = True
Let objApp.UserControl = True
Set objMap = objApp.ActiveMap
Set objLocNY = objMap.FindResults("New York, NY").Item(1)
Set objLocLA = objMap.FindResults("Los Angeles, CA").Item(1)
'Find the point on the screen midway between the two
X1% = objMap.LocationToX(objLocNY)
Y1% = objMap.LocationToY(objLocNY)
X2% = objMap.LocationToX(objLocLA)
Y2% = objMap.LocationToY(objLocLA)
x% = (X1% + X2%) / 2
y% = (Y1% + Y2%) / 2
Set objCenter = objMap.XYToLocation(x%, y%)
'Show the distance
objMap.Shapes.AddLine objLocNY, objLocLA
Set objTextbox = objMap.Shapes.AddTextbox(objCenter, 200, 50)
Distance# = objMap.Distance(objLocNY, objLocLA)
Let objTextbox.Text = "Distance, New York to Los Angeles: " & Distance#
End Sub

[C#]
void ShowDistanceNYtoLA()
{
ApplicationClass objApp = null;
MapPoint.Map objMap;
MapPoint.Shape objTextBox;
String Place1 = "New York, NY";
String Place2 = "Los Angeles,CA";
double Distance;

//Create an application class instance
objApp = new ApplicationClass();

//Set up application
objApp.Visible = true;
objApp.UserControl = true;
objMap = objApp.ActiveMap;
object Item = 1;

MapPoint.FindResults obNY = objMap.FindResults(Place1);
MapPoint.FindResults obLA= objMap.FindResults(Place2);
MapPoint.Location objNY = obNY.get_Item(ref Item) as MapPoint.Location;
MapPoint.Location objLA = obLA.get_Item(ref Item) as MapPoint.Location;
objNY.GoTo();
objLA.GoTo();

MapPoint.SelectedArea sa = objMap.SelectedArea;
MapPoint.Location objCenter = objMap.XYToLocation(sa.Left + sa.Width, sa.Top + sa.Height);

objMap.Shapes.AddShape(MapPoint.GeoAutoShapeType.geoShapeOval, objLA, 50, 30);
objMap.Shapes.AddLine(objNY.Location, objLA.Location);
Distance = objMap.Distance(objNY, objLA);

objTextBox = objMap.Shapes.AddTextbox(objCenter, 100, 50);
objTextBox.Text = ("Distance, NY to LA: " + Distance);
objMap.Altitude = 350;
}
Note This sample code is specifically for use in MapPoint North America; it is for illustration purposes only
//------------------------------------------------------------------------------------------

Do you know how "translate" this code to xHarbour + FWH?
Can you give me some tips?


Thanks,


George
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Mappoint Methods question

Post by lailton.webmaster »

George

where i do download this SDK ?

send link i make download and make translation it for you.

gracias :D
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Mappoint Methods question

Post by James Bott »

George,

As I said the locations have to be objects. Try this:

oStartLocation:= oActiveX:FindResults("205 Broadway, Lawrence, MA"):Item(1)
oEndLocation:= oActiveX:FindResults("77 Centre Street, Boston, MA"):Item(1)

msgInfo( oActiveX:Distance( oStartLocation, oEndLocation ), "Distance" )

Regards,
James
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: Mappoint Methods question

Post by George »

James,
Your suggestion seem logic but using the below code I get run mappoint but also the same error message: Error description: Error BASE/1004 Message not found: TACTIVEX:FINDRESULTS

local hToolBar, hStandard, oMapPoint, nDist
oActiveX = TActiveX():New( oWnd, "MapPoint.Control.16" )
oWnd:oClient = oActiveX // To fill the entire window surface

oActiveX:Do( "Newmap", 1 )
hToolBar = oActiveX:GetProp( "Toolbars" )
hStandard = OleGetProperty( hToolBar, "Item", "Standard" )
OleSetProperty( hStandard, "Visible", .T. )
oActiveX:GetProp( "Toolbars" )

oStartLocation:= oActiveX:FindResults("205 Broadway, Lawrence, MA"):Item(1)
oEndLocation:= oActiveX:FindResults("77 Centre Street, Boston, MA"):Item(1)

msgInfo( oActiveX:Distance( oStartLocation, oEndLocation ), "Distance" )


Laiton,
This is the link: http://msdn.microsoft.com/en-us/library/aa562314.aspx
You can download a Mappoint trial version from here: http://www.microsoft.com/mappoint/en-us ... t_download

Regards,

George
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Mappoint Methods question

Post by James Bott »

George,

Try this:

local hToolBar, hStandard, oMapPoint, nDist, oMap
oActiveX = TActiveX():New( oWnd, "MapPoint.Control.16" )
oWnd:oClient = oActiveX // To fill the entire window surface

oActiveX:Do( "Newmap", 1 )
hToolBar = oActiveX:GetProp( "Toolbars" )
hStandard = OleGetProperty( hToolBar, "Item", "Standard" )
OleSetProperty( hStandard, "Visible", .T. )
oActiveX:GetProp( "Toolbars" )

oMap := oActiveX:ActiveMap
oStartLocation:= oMap:FindResults("205 Broadway, Lawrence, MA"):Item(1)
oEndLocation:= oMap:FindResults("77 Centre Street, Boston, MA"):Item(1)

msgInfo( oActiveX:Distance( oStartLocation, oEndLocation ), "Distance" )


Regards,
James
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: Mappoint Methods question

Post by George »

Hi James,
Mappoint program open OK but now we get the error mesage in oMap := oActiveX:ActiveMap

Error description: Error BASE/1004 Message not found: TACTIVEX:ACTIVEMAP

Regards,

George
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Mappoint Methods question

Post by lailton.webmaster »

Try it.

Code: Select all | Expand

oMap := oActiveX:Do("ActiveMap")

 oStartLocation:= oMap:FindResults("205 Broadway, Lawrence, MA"):Item(1)
 oEndLocation:= oMap:FindResults("77 Centre Street, Boston, MA"):Item(1)
 
 oActiveX:Do("Distance", oStartLocation, oEndLocation )

 X1 := oMap:LocationToX(oStartLocation)
 Y1 := oMap:LocationToY(oStartLocation)
 X2 := oMap:LocationToX(oEndLocation)
 Y2 := oMap:LocationToY(oEndLocation)
 x  := (X1 + X2) / 2
 y  := (Y1 + Y2) / 2
objCenter := oMap:XYToLocation(x, y)

oMap:Shapes:AddLine( oStartLocation, oEndLocation)
objTextbox := oMap:Shapes:AddTextbox(objCenter, 200, 50)
Distance := oMap:Distance(objLocNY, objLocLA)
msginfo("Distance, x to Y é : " + Distance )
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: Mappoint Methods question

Post by George »

Lailton
I tried different approach but there are not working.
I am getting the same message
Error description: Error BASE/1004 Message not found: TACTIVEX:ACTIVEMAP

I think is more easy to get the distance by using google map API.

Regards,


George
lailton.webmaster
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Mappoint Methods question

Post by lailton.webmaster »

oMap := oActiveX:Do("ActiveMap")
ou
oMap := oActiveX:GetProp("ActiveMap")

what is your version of fwh ?
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: Mappoint Methods question

Post by George »

I am getting the following message:
Error description: Error BASE/1004 Class: 'NUMERIC' has no exported method: FINDRESULTS
Args:
[ 1] = N 0
[ 2] = C 205 Broadway, Lawrence, MA



I am using
FWH 9.06 + xHarbour Builder pro (Sep 08). Xharbou Pro uses PellesC not Borland.

Regards,

George
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Mappoint Methods question

Post by James Bott »

Check the valtype() of oMap right after it is created. From the error method it looks like it is a number.

msgInfo( valtype( oMap ) )

James
George
Posts: 726
Joined: Tue Oct 18, 2005 6:49 pm

Re: Mappoint Methods question

Post by George »

By using the following code:
local hToolBar, hStandard, oMapPoint, nDist, oMap
oActiveX = TActiveX():New( oWnd, "MapPoint.Control.16" )
oWnd:oClient = oActiveX // To fill the entire window surface

oMap := oActiveX:Do( "Newmap", 1 )
msginfo(valtype(oMap)) // NUMERIC
msginfo(oMap) //1706844
// If I try with oMap := oActiveX:Do("ActiveMap") or oMap := oActiveX:GetProp("ActiveMap")
// I get oMap = 0 and error message before open MapPoint

hToolBar = oActiveX:GetProp( "Toolbars" )
hStandard = OleGetProperty( hToolBar, "Item", "Standard" )
OleSetProperty( hStandard, "Visible", .T. )
oActiveX:GetProp( "Toolbars" )

// Here is the problem
oStartLocation:= oMap:FindResults("205 Broadway, Lawrence, MA"):Item(1)
oEndLocation:= oMap:FindResults("77 Centre Street, Boston, MA"):Item(1)

I get open MapPoint; see image:
[url]Image[/url]

But I get the error whe trying to use FindResults method.

I figure out that I am using FWH 8.05 + xHarbour Builder Pro Sep 08.
I will try with a most recent FWH version.

George
Post Reply