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 integrate maps.google with VFP? 1

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Before this thread was placed in the 'general' section but removed (together with given replies) by the management as it should be placed in here.

I like to have a button on a form which launches maps.google and shows the map with an adress which is on VFP form.

Is there any example of such a construct?

TIA
-Bart
 
Hello Bart;
we use the Mappoint class but somewhere along the line I have this code which I got from somewhere, cannot remember where nor the Author. Hopefully the Author will step forward when he/she see this and help you further...
Even though it displays the correct Google Map, it displays an error window. see Troubleshoot proc in code which I have just asterisked out... Good luck

Code:
*** create 2 parameters and pass the following:
***cStartAddress = "<<start Address>>" &&& 
***cDestAddress = "End Address>>"

google_directions(cStartAddress, cDestAddress)

Procedure google_directions
	Lparameters tcStartAddress, tcDestAddress
	Local CRLF, cUrl, oHTTP, nStart, nEnd, cResult, cTag, lTag, oIE
	Store Chr(13)+Chr(10) To CRLF

	Set Library To Home()+"Foxtools.fll"  Additive
	tcStartAddress=Chrtran(Alltrim(reduce(tcStartAddress)),Chr(32),"+")
	tcDestAddress =Chrtran(Alltrim(reduce(tcDestAddress )),Chr(32),"+")

	cUrl = "[URL unfurl="true"]http://www.google.com/maps?f=d&hl=en&saddr="[/URL] + tcStartAddress + "&daddr=" + tcDestAddress

	oHTTP = Createobject([MSXML2.XMLHTTP])
	oHTTP.Open("GET", cUrl, .F.)
	oHTTP.Send
	cResult=(oHTTP.ResponseText)

	nStart = Atc("<table class=\042dirsegment\042>", cResult, 1)
	cResult = Substr(cResult, nStart , Len(cResult)- nStart)
	nEnd = Atc("afterRoute\", cResult, 1)
	cResult = Strtran(Left(cResult, nEnd)+">", "<br>", " ")
	cResult = Strtran(cResult,"&#160;", Space(3))

	&&remove Html Tags
	lTags = .T.
	Do While lTags
		nStart = Atc("<", cResult, 1)
		nEnd = Atc(">", cResult, 1)
		cTag = Substr(cResult, nStart, 1 + nEnd - nStart)
		cResult = Strtran(cResult, cTag, Iif(Lower(cTag)=="</td>", CRLF,""))

		If Occurs("<",cResult)>0 And Occurs(">",cResult)>0
			lTags = .T.
		Else
			lTags = .F.
		Endif
	Enddo

	If Len(cResult)=1 &&troubleshoot
		oIE = Createobject("InternetExplorer.Application")
		oIE.Navigate2(cUrl)
		oIE.Visible=.T.
		*Messagebox("See what went wrong.", 0, "", 15000)
		*oIE.Quit
	Else
		&& sucess
		Strtofile(cResult,"cut.txt")
		Modify File cut.txt Nowait
	Endif
Endproc
 
Bart,

Here is the reply I posted to your original question in General Coding:

Bart,

This is probably easier than you think.

All you need is the URL that Google expects to receive. You can find that by doing an Ordinary Google Maps search in your web browser, using any address you know. Once that's done, copy the URL from the address bar to the clipboard.

You should see the address that you searched for within the URL (along with a lot of other stuff). For example, this is what I got when I searched for Willemstraat, in Eindhoven:

Code:
[URL unfurl="true"]http://maps.google.com/maps?q=[/URL][b]willemstraat+eindhoven[/b]
&sourceid=navclient-ff&ie=UTF-8&rlz=1B2GGGL_en___GB203

(I did that by entering the address in the Google toolbar in FireFox, and selecting the Maps option; it might work differently in other browsers.)

In your program, use STRTRAN() to change the address (willemstraat+eindhoven in this example) to the actual address that are interested in.

You now have the URL that you want to pass to Google. To do that, you can either add a Microsoft Web Browser control to a VFP form, and pass the URL to its Navigate2 method. Or, more simply, you can ShellExecute() the URL.

Give it a try. If you need any help on the individual steps, come back.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Imaginecorp, Thanks for your reply.
but..
Mike, This is exactly I looked for.
I do use the _hyperlinklabel with:
Code:
thisform._hyperlinklabel1.ctarget = "[URL unfurl="true"]http://maps.google.com/maps?q="+ALLTRIM(thisform.txtAdres.Value)+[/URL][+]+ALLTRIM(thisform.txtHuisNummer.value)+[+]+(thisform.txtPlaats.Value)
Code is updated in my custom 'afterskip' method.

Thanks for your reply and star worth!

btw: Willemstraat Eindhoven has meaning for you?

-Bart
 
Bart,

Yes, that looks good. Using the hyperlink makes it even easier.

When I was working for a certain electonics company in Apeldoorn, we used to sometimes visit their head office in Eindhoven. I remember Willemstraat was near our hotel (but can't remember much else about Eindhoven apart from the football team).

Thanks for the star.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I Agree... Mike's solution is short and sweet :} just the way it should be.
Our app is a little more complicated and so we use the Mappoint class which unfortunately needs a license to distribute...
 
In addition to my most recent solution.
It appears that if an adress is searched and found with this code than there is not always the pin showing the exact location in the street.
By closing the form and redo the search the pin is also there.
Anyone who knows how to directly get the pin on the map?
TIA
-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top