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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to embed a map an a VFP form 3

Status
Not open for further replies.

chriscboy

Programmer
Apr 23, 2002
150
GB
Hi,

I have been asked to provide some sort of map service on our company application so that when our consultants look at the sites they have to visit, they can easily view a map or some directions, based on the site post code.

What good mapping services are available and where would I start?

So far I have managed to get a map displayed using a form, a web browser control and a simple link to streetmap.co.uk.

Are there any services which could give directions as well?

Any help appreciated!

Chris
 
I know multimap can give directions ( - second tab). You need to enter 'To' and 'From' details on their web form.

And 'The AA' (Route Planner?) can do the same.

Not sure how you would 'automate' either of them though!

Neil

I like work. It fascinates me. I can sit and look at it for hours...
 

Chris,

If you want a really high-class (and expensive) solution, go for the MapX control in MapInfo. But be prepared to spend some time developing with it.

For a quick-and-dirty solution, I use the same approach as your original suggestion: streetmap.co.uk displayed in a web browser control embedded in a form. It works well and is easy to implement.

If you do stay with it, it's worth paying the small fee they charge to turn off the adverts, as these detract from the professional appearance of the form. At the very least, get your users to install a utility like Turnflash, which turns off the distracting animations.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 

Chris

I don't know if Mapquest exists in the UK, but a free solution might be using the suggestions in faq184-4666.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Below is a crude example based on the solution I am going to use. It involves using a form, web browser control and links to 3 different map sites (google,multimap, and streetmap).

After asking my users for their preferences for a map site I got a lot of different answers, but the most common were the three mentioned above, so I have included a drop down to give the user the choice of map.

Once they select the site, they enter a 'destination' post code, and click on OK. I then load the appropriate site by constructing a URL , then navigating to that URL in the browser.

This is a very basic example, and needs improvements such as being able to search on a street name/town or the ability to resize the window.

Copy the code below into a prg and run. Don't forget to change variable lcStartPostCode to the post code of your own address:

Code:
Public oForm
oForm = CreateObject("mapclass")
oForm.show

DEFINE CLASS mapclass AS form

	Height = 573
	Width = 741
	DoCreate = .T.
	Name = "form"
	Caption = "Map form"

	ADD OBJECT oweb AS olecontrol WITH ;
		Top = 12, ;
		Left = 12, ;
		Height = 468, ;
		Width = 720, ;
		Name = "oWeb", ;
		OleClass = "Shell.Explorer.2"

	ADD OBJECT txtpostcode AS textbox WITH ;
		Height = 25, ;
		Left = 300, ;
		Top = 492, ;
		Width = 96, ;
		Name = "txtPostCode"


	ADD OBJECT cmdfind AS commandbutton WITH ;
		Top = 492, ;
		Left = 408, ;
		Height = 27, ;
		Width = 48, ;
		Caption = "OK", ;
		Name = "cmdFind"


	ADD OBJECT cbowebsites AS combobox WITH ;
		ColumnCount = 0, ;
		ColumnWidths = "", ;
		RowSourceType = 1, ;
		RowSource = "Google Maps,Streetmap.co.uk,Multimap.co.uk", ;
		FirstElement = 1, ;
		Height = 24, ;
		IncrementalSearch = .F., ;
		Left = 72, ;
		NumberOfElements = 0, ;
		Style = 2, ;
		Top = 492, ;
		Width = 120, ;
		BoundTo = .T., ;
		Name = "cboWebSites"


	ADD OBJECT label2 AS label WITH ;
		FontBold = .T., ;
		FontUnderline = .T., ;
		Caption = "Web-site", ;
		Height = 17, ;
		Left = 12, ;
		Top = 492, ;
		Width = 53, ;
		Name = "Label2"


	ADD OBJECT label4 AS label WITH ;
		FontBold = .T., ;
		FontUnderline = .T., ;
		Caption = "Site destination", ;
		Height = 17, ;
		Left = 204, ;
		Top = 492, ;
		Width = 96, ;
		Name = "Label4"


	PROCEDURE Load
		Sys(2333,1)
	EndProc
	
	PROCEDURE cmdfind.Click
		Local lcURL
		Local lcStartPostCode
		lcURL=""

		* This is where the map starts from (used for google search only)
		lcStartPostCode="RH13 5QH"

		Do Case

			Case Thisform.cboWebSites.ListIndex = 1			&& Google

				lcURL = "[URL unfurl="true"]http://maps.google.co.uk/maps?f=d&hl=en"[/URL]
				lcURL = lcURL + "&saddr="+Chrtran(Alltrim(lcStartPostCode)," ","+")
				lcURL = lcURL + "&daddr="+Chrtran(Alltrim(This.Parent.txtPostCode.Value)," ","+")
				lcURL = lcURL + "&btnG=Search"

			Case Thisform.cboWebSites.ListIndex = 2			&& Streetmap

				lcURL = "[URL unfurl="true"]http://www.streetmap.co.uk/streetmap.dll?postcode2map?"[/URL]
				lcURL = lcURL + Chrtran(Alltrim(This.Parent.txtPostCode.Value)," ","+")

			Case Thisform.cboWebSites.ListIndex = 3			&& Multimap

				lcURL = "[URL unfurl="true"]http://www.multimap.com/map/browse.cgi?client=public&search_result=&cidr_client=none&lang=&db=GB&keepicon=true&pc="+Chrtran(Alltrim(This.Parent.txtPostCode.Value),"[/URL] ","+")+"&advanced=true&addr2=&client=public&addr3=&overviewmap="

			Otherwise

				MessageBox ("Please select a web site.")
				Return

		EndCase

		This.Parent.oWeb.Navigate(lcURL)
	ENDPROC


ENDDEFINE
 

Lee,

I would interested in knowing how you achieved this?

Chris has given you the code to do it, which is similar to my own. The Streetmap site also has a tool that generates a URL for any postcode (press the "How to link to us" button on their main page). You can examine the generated URL to see how it is constructed, and then just plug in the variable information, along the lines that Chris has demonstrated.

It works well, apart from the annoying adverts.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Chriscboy
Thats terrific and works perfect. The cosmetic side is not really an issue as this can done regardless.

Worthy of a star!

Mike
Thank you as well for your post. I found the link which again is very useful.

Thanks both

Lee

Visual FoxPro Versions: 6 & 9
Operating System: Windows XP
 
Playing with the form, Has anyone seen a site that will change phone number into address that google can read?
wjw
 

White,

Has anyone seen a site that will change phone number into address that google can read?

You mean you want a "reverse telephone directory"? That doesn't exist in the UK, as far as I know, but in might in other countries.

If you are looking for a particular address, you could always try entering the phone number in Google.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Actually, if you type a US phone number into Google, it'll look it up for you.

Tamar
 
Tamar,
Yes i have used that interactivly a lot. I guess the chore would be to "catch" the "PhoneBook" result from google, parse the address from it, and stuff that into value of the To portion of the form. This would return a map for deilvery for an item from a start point which would be static to a specific phone number provided, google returned a result for the number submitted. It will be the seperate "submitting: and "catching" that will be the challange here i think!
wjwjr
 
Juris,


That's certainly true of the map they show for my own city.

Another reason I don't like Multimap is that it is purely a road map - at least, that's true in the UK and USA. It's very poor at showing physical features and landmarks -- not even something as obvious as railway stations.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top