Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a VFP DLL to use Mapquest in a VFP application.

Internet

How to create a VFP DLL to use Mapquest in a VFP application.

by  Mike Gagnon  Posted    (Edited  )
Note: This technique can be also done using a VFP class rather then a DLL.
Note 2 :MapQuest is a website that allows you to find a portion of a map that contains the address,city, country and zip code requested. This has been tested for Canada and the US.
[ol][li]Create a directory with Windows Explorer and call the directory "mapquest".[/li]
[li]In FoxPro poit the default directory to the "mapquest" directory. Tolls->Options->File locations->Default directory.[/li]
[li]Create a blank project (do not use the project wizard), and call the project "mapquest".[/li]
[li] Add a custom class (called "internet").[/li]
[li]Add 3 methods to the custom class (searchURL,showdestination,URLencode).[/li]
[li]In the 'searchURL" method put the following code:
Code:
LPARAMETERS tcURL
oBrowser = CREATEOBJECT("internetexplorer.application")
oBrowser.navigate(tcURL)
oBrowser.visible = .t.
[/li]
[li]In the 'showDestination' method put the following code:
Code:
LPARAMETERS lcStreet,lcCity,lcState,lcZip,lcCountry
IF EMPTY(lcStreet)
 lcStreet = ""
ENDIF
IF EMPTY(lcState)
   lcState = ""
ENDIF 
IF EMPTY(lcZip)
   lcZip = ""
ENDIF
IF EMPTY(lcCountry)
   lcCountry = "US"
ENDIF
IF EMPTY(lcCity)
  lcCity=""
ENDIF
this.searchurl("http://www.mapquest.com/maps/map.adp?country=" + ;
       lcCountry + "&addtohistory=&address=" + ;
       this.UrlEncode(lcStreet) + ;
       "&city=" + this.UrlEncode(lcCity) + "&state=" + ;
       this.UrlEncode(lcState) +  "&zipcode=" + ;
       this.UrlEncode(lcZip) + "&homesubmit=Get+Map&size=big")
[/li]
[li]In the URLencode method put (this code was borrowed from www.West-Wind.com):
Code:
LPARAMETERS  tcValue, llNoPlus
LOCAL lcResult, lcChar, lnSize, lnX
lcResult=""
FOR lnX=1 to len(tcValue)
   lcChar = SUBSTR(tcValue,lnX,1)
   IF ATC(lcChar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") > 0
      lcResult=lcResult + lcChar
      LOOP
   ENDIF
   IF lcChar=" " AND !llNoPlus
      lcResult = lcResult + "+"
      LOOP
   ENDIF
   lcResult = lcResult + "%" + RIGHT(transform(ASC(lcChar),"@0"),2)
ENDFOR 
RETURN lcResult
[/li]
[li]Close the project. Open the class browser and load the internet class library and right-mouse on it and set it to OLEPublic. && This is required for a DLL[/li]
[li]Re-open the project and compile it using the "multi-threaded COM server DLL."[/li]
[li] Now you are ready to call the DLL to locate a portion of a map on mapQuest, using the 4 required parameters. In the command window try:
Code:
oMap = NEWOBJECT("mapquest.internet")
oMap.ShowDestination("134 ave Willobank","Pointe-claire","QC",;
"H9R3K8","CA")
[/li]

P.S. If the DLL is to be used on a user's computer rather than the development computer, the DLL needs to be registered.

Mike Gagnon




Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top