FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Mappoint Methods question
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Mappoint Methods question
Posted: Fri Aug 07, 2009 02:06 AM
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 (fw): Select all Collapse
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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Mappoint Methods question
Posted: Fri Aug 07, 2009 06:25 AM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Mappoint Methods question
Posted: Fri Aug 07, 2009 07:36 AM

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

try it.

:lol:

Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Mappoint Methods question
Posted: Fri Aug 07, 2009 01:11 PM

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

Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Mappoint Methods question
Posted: Fri Aug 07, 2009 01:22 PM

George

where i do download this SDK ?

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

gracias :D

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Mappoint Methods question
Posted: Fri Aug 07, 2009 02:55 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Mappoint Methods question
Posted: Sat Aug 08, 2009 03:06 PM

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

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Mappoint Methods question
Posted: Sun Aug 09, 2009 04:12 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Mappoint Methods question
Posted: Mon Aug 10, 2009 02:18 PM
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
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Mappoint Methods question
Posted: Tue Aug 11, 2009 09:18 AM
Try it.

Code (fw): Select all Collapse
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 )
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Mappoint Methods question
Posted: Tue Aug 11, 2009 03:23 PM
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
Posts: 603
Joined: Sun May 04, 2008 08:44 PM
Re: Mappoint Methods question
Posted: Tue Aug 11, 2009 03:30 PM

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

what is your version of fwh ?

Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Mappoint Methods question
Posted: Tue Aug 11, 2009 04:26 PM
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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Mappoint Methods question
Posted: Tue Aug 11, 2009 06:29 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: Mappoint Methods question
Posted: Tue Aug 11, 2009 07:13 PM
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:
" rel="noopener">

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