Google Maps

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Google Maps

Post by Michael Vogel »

Hi,

I thought, everything will be so easy now :?

I just want to capture a map from google maps to get an idea where some GPS data has been collected (see screenshots). I paused the project because of my problems with TransformSprite3D, but now it should be the right time for the next try (or not) :lol:...

Because waldschrath gave me the right tip, I should be able to get a map copied into a bitmap.

But there are still more problems than expected:

Code: Select all

Procedure SavePicture()
	UsePNGImageEncoder()
	windowhandle=GadgetID(1)
	GetClientRect_(windowhandle, @cr.RECT)
	CreateImage(0, cr\right-cr\left, cr\bottom-cr\top, 24)
	hdc=StartDrawing(ImageOutput(0))
	SendMessage_(windowhandle, #WM_PRINT, hdc, #PRF_CLIENT|#PRF_CHILDREN|#PRF_ERASEBKGND)
	StopDrawing()
	Debug SaveImage(0, "c:\Screenshot.png",#PB_ImagePlugin_PNG)
EndProcedure
Procedure InitHTMLCode()

	Global HTML.s

	Repeat
		Read.s zeile.s
		If zeile="*"
			Break
		EndIf
		HTML+zeile+#CRLF$
	ForEver

	CreateFile(0,"c:\test.html")
	WriteString(0,HTML)
	CloseFile(0)

EndProcedure

InitHTMLCode()
If OpenWindow(0,0,0,800,500,"X",#PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget 
|#PB_Window_MaximizeGadget | #PB_Window_ScreenCentered);|#PB_Window_Invisible)

	; First Approach...
	; WebGadget(1, 0, 0, 800, 500,HTML);,#PB_Web_Mozilla )

	; Second Approach...
	WebGadget(1, 0, 0, 800, 500, "");,#PB_Web_Mozilla )
	SetGadgetItemText(1,#PB_Web_HtmlCode,HTML)

	; Third Approach...
	;WebGadget(1, 0, 0, 800, 500, "file://c|/test.html");,#PB_Web_Mozilla )
	
	saveflag=0

	Repeat
		Event = WaitWindowEvent(100)

		If saveflag=1
			Debug "wait..."
			If GetGadgetAttribute(1,#PB_Web_Busy)=0
				Delay(10)
				Debug "Save now!"
				saveflag=2
				Repeat
					WindowEvent()
				Until WaitWindowEvent(0)=0
				SavePicture()
				End

			EndIf
		EndIf


		Select Event

		Case #PB_Event_Gadget
			Select EventGadget()
			Case 1
				Select EventType()
				Case #PB_Event_DataReceived
					;Debug "Data"
				Case  #PB_EventType_DownloadEnd
					If saveflag=0
						saveflag=1
					EndIf
					;Debug "Download"
				Case #PB_EventType_StatusChange
					;Debug "Changes"
				EndSelect
			EndSelect
		EndSelect
	Until Event=#PB_Event_CloseWindow


EndIf



DataSection
	Data.s "<!DOCTYPE html PUBLIC "+#DQUOTE$+"-//W3C//DTD XHTML 1.0 Strict//EN"+#DQUOTE$
	Data.s "	"+#DQUOTE$+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"+#DQUOTE$+">"
	Data.s "<html xmlns="+#DQUOTE$+"http://www.w3.org/1999/xhtml"+#DQUOTE$+">"
	Data.s "	<head>"
	Data.s "		<meta http-equiv="+#DQUOTE$+"content-type"+#DQUOTE$+" content="+#DQUOTE$+"text/html; charset=utf-8"+#DQUOTE$+"/>"
	Data.s "		<title>Google Maps JavaScript API Example</title>"
	Data.s "		<script src="+#DQUOTE$+"http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA45pVCvzTSuvt6AO3V1TbBhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxS-e6HzAF46gYlJucyeiXO5uoeS0w"+#DQUOTE$
	Data.s "			type="+#DQUOTE$+"text/javascript"+#DQUOTE$+"></script>"
	Data.s "		<script type="+#DQUOTE$+"text/javascript"+#DQUOTE$+">"
	Data.s "		//<![CDATA["
	Data.s "		function load() {"
	Data.s "			if (GBrowserIsCompatible()) {"
	Data.s "				var map = new GMap2(document.getElementById("+#DQUOTE$+"map"+#DQUOTE$+"));"
	Data.s "				map.setCenter(new GLatLng(48.000, 16.000), 15);"
	Data.s "				map.hideControls();"
	Data.s "			}"
	Data.s "		}"
	Data.s "		//]]>"
	Data.s "		</script>"
	Data.s "	</head>"
	Data.s "	<body onload="+#DQUOTE$+"load()"+#DQUOTE$+" onunload="+#DQUOTE$+"GUnload()"+#DQUOTE$+">"
	Data.s "		<div id="+#DQUOTE$+"map"+#DQUOTE$+" style="+#DQUOTE$+"width:500px;height:300px"+#DQUOTE$+"></div>"
	Data.s "		</body>"
	Data.s "</html>"
	Data.s "*"
EndDataSection
The results of the different approaches are totally different and i don't know why...
- first approach, nothing of the map will be loaded :oops:
- second approach, I'll get an google maps error, that the API is wrong (I don't know why this message appears nor how to hide such pop ups) :evil:
- the third approach works, but I don't like to create a temp file :?

Can anyone tell me, why all these things leads to completely different results? Any idea how to "optimize" on of the first approaches?

Thanks,
Michael
Last edited by Michael Vogel on Fri Feb 20, 2009 3:23 pm, edited 1 time in total.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Just an update - and two remarks...

:( the problems of the first posting are still present (I found no way to be able to get a map without creating a temp file) --- any ideas?

:) I was able to get an image of a map which contains exactly the area defined by a lower left and a upper right corner!

The only (simple) thing which has do be done, is to remove the pixels at the top or bottom which are given because the upper and lower "half" of the map do not have the same pixel height because of the mercator projection of the globe. Anyhow, the needed information for that will be displayed in the debugging window... :wink:

And don't forget to use your own ID :roll:

Code: Select all

#ZweiPi=#PI+#PI
#PiHalbe=#PI/2
#PiTeil=#PI/18
#PiRadiant=#PI/180
#PiGrad=180/#PI

Macro Radiant(x)
	(x*#PiRadiant)
	;Procedure.d Radiant(x.d)
	;	ProcedureReturn x*#PiRadiant
	;EndProcedure
EndMacro

Procedure.d GoogleMapsHeight(grad.d)
	#Skalierung256Pixel=81.75513713869655
	ProcedureReturn Log(Tan(#PI/4+Radiant(grad)/2))*#Skalierung256Pixel
EndProcedure
Procedure.d GoogleMapsWidth(grad.d)
	ProcedureReturn 256*Radiant(grad)/#ZweiPi
EndProcedure


Procedure GoogleMaps()

	Protected OptMapsZoom=256;		(minimale) Zielhöhe der Karte in Pixel

	Protected LonA.d,LatA.d,PixA.d;		Punkt links unten (A)
	Protected LonB.d,LatB.d,PixB.d;		Punkt rechts oben (B)
	Protected LonM.d,LatM.d,PixM.d;		Punkte in der "Mitte" (M)

	Protected BiggerFlag;					Definition der größeren Kartenhälfte
	Protected BiggerSize.d;				Pixelhöhe der größeren Kartenhälfte
	Protected MapX,MapY,MapZoom;		Kartendimensionen

	Protected Webpage.s,s.s;			Texte
	Protected Webflag,Webhandle;		Download-Status, Handle

	LonA=15
	LonB=20
	LatA=40
	LatB=50

	; Koordinaten ordnen
	If LonB<LonA : Swap LonA,LonB : EndIf
	If LatB<LatA : Swap LatA,LatB : EndIf

	; Kartenmittelpunkt
	LonM=(LonA+LonB)/2
	LatM=(LatA+LatB)/2

	; Verzerrung der Mercatorprojektion bezüglich Mittelpunkt prüfen...
	If LatA<0
		If LatB<0
			BiggerFlag=2;	untere Kartenhälfte (A-M) ist größer (A und B auf südlicher Hemisphäre)
		ElseIf LatA>-LatB
			BiggerFlag=1;	obere Kartenhälfte (M-B) ist größer (Distanz A-Äquator kleiner als B-Äquator)
		Else
			BiggerFlag=2;	untere Kartenhälfte (A-M) ist größer (Distanz A-Äquator größer als B-Äquator)
		EndIf
	Else
		BiggerFlag=1;		obere Kartenhälfte (M-B) ist größer (A und B auf nördlicher Hemisphäre)
	EndIf

	; Breitengrade in Pixel umrechnen...
	PixA=GoogleMapsHeight(LatA)
	PixM=GoogleMapsHeight(LatM)
	PixB=GoogleMapsHeight(LatB)

	; Größere Kartenhälfte bestimmen (Kartenverzerrung auf Nord-/Südhalbkugel)
	If BiggerFlag=1
		BiggerSize=PixB-PixM
	Else
		BiggerSize=PixM-PixA
	EndIf
	If BiggerSize<0
		BiggerSize=-BiggerSize
	EndIf

	BiggerSize*2; 			Kartenhöhe = doppelte Höhe der größeren Kartenhälfte

	MapZoom=1
	MapX=2
	While BiggerSize<OptMapsZoom
		MapZoom+1
		MapX*2
		BiggerSize*2
		PixA*2
		PixM*2
		PixB*2
	Wend

	; Kartendimensionen in Pixel
	MapY=BiggerSize
	MapX=(GoogleMapsWidth(LonB)-GoogleMapsWidth(LonA))*MapX

	; Informationen zur Google Maps Karte
	Debug "Google Maps:"
	Debug "Center: "+StrF(LonM,2)+"/"+StrF(LatM,2)
	Debug "Zoom: " +Str(MapZoom)
	Debug ""
	Debug "Map Total Height: "+StrF(BiggerSize,1)
	Debug "Map Total Width: "+StrF(MapX,1)
	Debug "Upper Half Height: "+StrF(PixM-PixA,1)
	Debug "Lower Half Height: "+StrF(PixB-PixM,1)
	Debug ""

	; HTML-Seite für Google Maps kreieren
	Restore Webcontent
	Repeat
		Read.s s
		s=ReplaceString(s,"#K","YOUR Google Maps Key!")
		s=ReplaceString(s,"#A",StrD(LatM,8))
		s=ReplaceString(s,"#B",StrD(LonM,8))
		s=ReplaceString(s,"#Z",Str(MapZoom))
		s=ReplaceString(s,"#X",Str(MapX))
		s=ReplaceString(s,"#Y",Str(MapY))
		Webpage+s+#CRLF$
	Until s="</html>"


	; Google Maps holen
	If OpenWindow(0,0,0,800,500,"X",#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget | 
#PB_Window_MaximizeGadget | #PB_Window_ScreenCentered);|#PB_Window_Invisible)
		; First Approach...
		; WebGadget(1, 0, 0, 800, 500,HTML);,#PB_Web_Mozilla )

		; Second Approach...
		;WebGadget(1, 0, 0, 800, 500, "");,#PB_Web_Mozilla )
		;SetGadgetItemText(1,#PB_Web_HtmlCode,HTML)

		; Third Approach...
		#Webfile="Forerunner.htm"
		If CreateFile(0,"c:\"+#Webfile)
			WriteStringN(0,Webpage)
			CloseFile(0)
		EndIf
		WebGadget(1,0,0,800,500,"file://c|/"+#Webfile);,#PB_Web_Mozilla )

		Enumeration
			#FlagIdle
			#FlagLoading
			#FlagMapLoaded
			#FlagMapSaved
			#FlagTimeout
		EndEnumeration

		Webflag=#FlagIdle

		Repeat
			Select WaitWindowEvent(100)

			Case #PB_Event_Gadget
				Select EventGadget()
				Case 1
					Select EventType()
					Case #PB_Event_DataReceived,#PB_EventType_StatusChange
						If Webflag<#FlagLoading : Webflag=#FlagLoading : EndIf
					Case  #PB_EventType_DownloadEnd
						If (Webflag=#FlagLoading) And (GetGadgetAttribute(1,#PB_Web_Busy)=0)
							Webflag=#FlagMapLoaded
							; Google Maps Karte speichern...
							UsePNGImageEncoder()
							Webhandle=GadgetID(1)
							GetClientRect_(Webhandle,@cr.RECT)
							CreateImage(0,cr\right-cr\left,cr\bottom-cr\top,24)
							hdc=StartDrawing(ImageOutput(0))
							SendMessage_(Webhandle,#WM_PRINT,hdc,#PRF_CLIENT|#PRF_CHILDREN|#PRF_ERASEBKGND)
							StopDrawing()
							If SaveImage(0,"c:\Screenshot.png",#PB_ImagePlugin_PNG)
								Webflag=#FlagMapSaved
							EndIf

						EndIf
					EndSelect

				EndSelect
			EndSelect

		Until Webflag>#FlagMapLoaded

	EndIf


	DataSection
		#Q$=#DQUOTE$

		Webcontent:
		Data.s "<!DOCTYPE html PUBLIC "+#Q$+"-//W3C//DTD XHTML 1.0 Strict//EN"+#Q$
		Data.s #Q$+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"+#Q$+">"
		Data.s "<html	xmlns="+#Q$+"http://www.w3.org/1999/xhtml"+#Q$+">"
		Data.s "<head>"
		Data.s "<meta	http-equiv="+#Q$+"content-type"+#Q$+" content="+#Q$+"text/html; charset=utf-8"+#Q$+"/>"
		Data.s "<title>Forerunner Google Maps</title>"
		Data.s "<style	type="+#Q$+"text/css"+#Q$+">"
		Data.s "	body{margin:0px;}"
		Data.s "</style>"
		Data.s "<script	src="+#Q$+"http://maps.google.com/maps?file=api&v=2&key=#K"+#Q$
		Data.s "	type="+#Q$+"text/javascript"+#Q$+"></script>"
		Data.s "<script	type="+#Q$+"text/javascript"+#Q$+">"
		Data.s "	//<![CDATA["
		Data.s ""
		Data.s "	function load() {"
		Data.s "	if (GBrowserIsCompatible()) {"
		Data.s "		var map = new GMap2(document.getElementById("+#Q$+"map"+#Q$+"));"
		Data.s "		map.setCenter(new GLatLng(#A,#B),#Z);"
		Data.s "		map.addOverlay(new GMarker(new GLatLng(#A,#B)));"
		Data.s "		map.hideControls();"
		Data.s "		map.disableDragging();"
		Data.s "		}"
		Data.s "	}"
		Data.s "	//]]>"
		Data.s "</script>"
		Data.s "</head>"
		Data.s "	<body onload="+#Q$+"load()"+#Q$+" onunload="+#Q$+"GUnload()"+#Q$+">"
		Data.s "		<div id="+#Q$+"map"+#Q$+" style="+#Q$+"width:#Xpx;height:#Ypx"+#Q$+"></div>"
		Data.s "	</body>"
		Data.s "</html>"
	EndDataSection

EndProcedure

GoogleMaps()
Last edited by Michael Vogel on Fri Feb 20, 2009 3:24 pm, edited 1 time in total.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

This thread is my first big monologue :lol:

The Web Gadget keeps quite a lot secrets...

• how to see, if a page has been (fully*) loaded or not?

If there is no internet available, the example above still says "ok" (#PB_Web_StatusMessage) and the #PB_Web_HTML_Code keeps unchanged. :(
*) there's one more issue, when it takes too long to get all parts of the map from Google Maps. The state will be already #PB_EventType_DownloadEnd which is not true, so the resulting picture also includes some greyed squares :cry:

• how to get rid of creating a local file?

For me this seems not very elegant because it takes time and disk space to create the file...
When the program have to work on all PCs, I must write this file to the current directory (or the temp dir). In my case I would also have to convert the "C:\Dokumente und Einstellungen\Michael\Lokale Einstellungen\Temp" to "file:///c|Dokumente%20und%20Ein...." what means additional work also.

Maybe someone had to fight already with similar problems - any idea is welcome,

Michael
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Hehe :lol:

I need still answers for the questions above, but the code is now fully functional (so it's nearby a entry for the tips section :wink:) -- even the top or bottom pixels are removed exactly to get the map you need :P

:arrow: change the OptMapsZoom value for bigger maps
:arrow: change LatA/LonA and LatB/LonB for the rectangle you want to see
:arrow: don't forget to insert your own Google Maps key in the data section
:arrow: any ideas how to get the (accurat) information, when the map has been fully loaded would be great
:arrow: any tip, how to be able to get the thing running without creating a temp html file would be also nice

Michael

Code: Select all

#ZweiPi=#PI+#PI
#PiHalbe=#PI/2
#PiTeil=#PI/18
#PiRadiant=#PI/180
#PiGrad=180/#PI

EnableExplicit

Macro Radiant(x)
	(x*#PiRadiant)
	;Procedure.d Radiant(x.d)
	;	ProcedureReturn x*#PiRadiant
	;EndProcedure
EndMacro
Procedure Waiter(time)
	time+ElapsedMilliseconds()
	Repeat
		WaitWindowEvent(5)
	Until ElapsedMilliseconds()>time
EndProcedure
Procedure.d GoogleMapsHeight(grad.d)
	#Skalierung256Pixel=81.75513713869655
	ProcedureReturn Log(Tan(#PI/4+Radiant(grad)/2))*#Skalierung256Pixel
EndProcedure
Procedure.d GoogleMapsWidth(grad.d)
	ProcedureReturn 256*Radiant(grad)/#ZweiPi
EndProcedure

Procedure GoogleMaps()

	Protected OptMapsZoom=200;		(minimale) Zielhöhe der Karte in Pixel
	Protected Delay=20;					Verzögerungswert in 1/4-Sekunden

	Protected LonA.d,LatA.d,PixA.d;		Punkt links unten (A)
	Protected LonB.d,LatB.d,PixB.d;		Punkt rechts oben (B)
	Protected LonM.d,LatM.d,PixM.d;		Punkte in der "Mitte" (M)

	Protected BiggerFlag;					Definition der größeren Kartenhälfte
	Protected BiggerSize.d;				Pixelhöhe der größeren Kartenhälfte
	Protected MapX,MapY,MapZoom;		Kartendimensionen

	Protected Webpage.s,s.s;			Texte
	Protected Webflag,Webhandle;		Download-Status, Handle

	; Just for Testing...
	If 1
		LonA=-10
		LonB=20
		LatA=40
		LatB=60
	Else
		LonA=15.118007199999999
		LatA=48.2185548
		LonB=15.350329500000001
		LatB=48.377523400000001
	EndIf

	; Koordinaten ordnen
	If LonB<LonA : Swap LonA,LonB : EndIf
	If LatB<LatA : Swap LatA,LatB : EndIf

	; Kartenmittelpunkt
	LonM=(LonA+LonB)/2
	LatM=(LatA+LatB)/2

	; Verzerrung der Mercatorprojektion bezüglich Mittelpunkt prüfen...
	If LatA<0
		If LatB<0
			BiggerFlag=1;	untere Kartenhälfte (A-M) ist größer (A und B auf südlicher Hemisphäre)
		ElseIf LatA>-LatB
			BiggerFlag=0;	obere Kartenhälfte (M-B) ist größer (Distanz A-Äquator kleiner als B-Äquator)
		Else
			BiggerFlag=1;	untere Kartenhälfte (A-M) ist größer (Distanz A-Äquator größer als B-Äquator)
		EndIf
	Else
		BiggerFlag=0;		obere Kartenhälfte (M-B) ist größer (A und B auf nördlicher Hemisphäre)
	EndIf

	; Breitengrade in Pixel umrechnen...
	PixA=GoogleMapsHeight(LatA)
	PixM=GoogleMapsHeight(LatM)
	PixB=GoogleMapsHeight(LatB)

	; Größere Kartenhälfte bestimmen (Kartenverzerrung auf Nord-/Südhalbkugel)
	If BiggerFlag=0
		BiggerSize=PixB-PixM
	Else
		BiggerSize=PixM-PixA
	EndIf
	If BiggerSize<0
		BiggerSize=-BiggerSize
	EndIf

	BiggerSize*2; 			Kartenhöhe = doppelte Höhe der größeren Kartenhälfte

	MapZoom=1
	MapX=2
	While BiggerSize<OptMapsZoom
		MapZoom+1
		MapX*2
		BiggerSize*2
		PixA*2
		PixM*2
		PixB*2
	Wend

	; Kartendimensionen in Pixel
	MapY=BiggerSize
	MapX=(GoogleMapsWidth(LonB)-GoogleMapsWidth(LonA))*MapX

	; Informationen zur Google Maps Karte
	Debug "Google Maps:"
	Debug "Center: "+StrF(LonM,2)+"/"+StrF(LatM,2)
	Debug "Zoom: " +Str(MapZoom)
	Debug ""
	Debug "Map Total Height: "+StrF(BiggerSize,1)
	Debug "Map Real Height: "+StrF(PixB-PixA,1)
	Debug "Map Total Width: "+StrF(MapX,1)
	Debug "Upper Half Height: "+StrF(PixM-PixA,1)
	Debug "Lower Half Height: "+StrF(PixB-PixM,1)
	Debug ""

	; HTML-Seite für Google Maps kreieren
	Restore Webcontent
	Repeat
		Read.s s
		s=ReplaceString(s,"#A",StrD(LatM,8))
		s=ReplaceString(s,"#B",StrD(LonM,8))
		s=ReplaceString(s,"#Z",Str(MapZoom))
		s=ReplaceString(s,"#X",Str(MapX))
		s=ReplaceString(s,"#Y",Str(MapY))
		Webpage+s+#CRLF$
	Until s="</html>"


	; Google Maps holen
	OpenWindow(0,0,0,MapX,MapY,"Google Maps",#PB_Window_ScreenCentered|#PB_Window_BorderLess)

	#Web_Gadget=1
	
	Select 3

	Case 1; First Approach... (Site not found)
		WebGadget(#Web_Gadget,0,0,MapX,MapY,Webpage);,#PB_Web_Mozilla )

	Case 2; Second Approach... (Illegal Google ID)
		WebGadget(#Web_Gadget,0,0,MapX,MapY, "");,#PB_Web_Mozilla )
		SetGadgetItemText(#Web_Gadget,#PB_Web_HtmlCode,Webpage)

	Case 3; Third Approach... (works)
		#Webfile="Forerunner.htm"
		If CreateFile(0,"c:\"+#Webfile)
			WriteStringN(0,Webpage)
			CloseFile(0)
		EndIf
		WebGadget(#Web_Gadget,0,0,MapX,MapY,"file://c|/"+#Webfile,#PB_Web_Mozilla)
	EndSelect

	DisableGadget(#Web_Gadget,1)
	;SetGadgetAttribute(#Web_Gadget,#PB_Web_BlockPopupMenu,1)
	Protected Browser.IWebBrowser2=GetWindowLong_(GadgetID(#Web_Gadget),#GWL_USERDATA)
	If Browser
		Browser\put_Silent(#True)
		;Browser\put_RegisterAsDropTarget(#VARIANT_FALSE)
	EndIf

	Enumeration
		#FlagIdle
		#FlagLoading
		#FlagMapLoaded
		#FlagMapSaving
		#FlagMapSaved
		#FlagTimeout
		#FlagMapPanik
	EndEnumeration

	Webflag=#FlagIdle

	Repeat

		Select WaitWindowEvent(250)

		Case #PB_Event_Gadget

			Select EventGadget()
			Case #Web_Gadget
				Select EventType()
				Case #PB_Event_DataReceived,#PB_EventType_StatusChange
					If Webflag<#FlagLoading : Webflag=#FlagLoading : EndIf

				Case  #PB_EventType_DownloadEnd
					Webflag=#FlagMapLoaded

				EndSelect; Status

			EndSelect; Gadget

		EndSelect; Event

		Select Webflag
		Case #FlagMapLoaded
			Waiter(250)
			If Delay
				Delay-1
				Debug -Delay
			Else
				Webflag=#FlagMapSaving
			EndIf

		Case #FlagMapSaving

			Debug GetGadgetItemText(#Web_Gadget,#PB_Web_StatusMessage)

			; Google Maps Karte speichern...
			UsePNGImageEncoder()
			Webhandle=GadgetID(#Web_Gadget)

			#Image_Gadget=1

			CreateImage(#Image_Gadget,MapX,MapY,24)
			SendMessage_(Webhandle,#WM_PRINT,StartDrawing(ImageOutput(#Image_Gadget)),#PRF_CLIENT|#PRF_CHILDREN|#PRF_ERASEBKGND)
			StopDrawing()

			If BiggerFlag
				; südlichere Seite ist größer, also den oberen Rand auslassen...
				BiggerFlag=BiggerSize-PixB-PixA
			EndIf

			GrabImage(#Image_Gadget,#Image_Gadget,0,BiggerFlag,MapX,PixB-PixA)
			Debug "Map Corners: 0 - "+Str(BiggerFlag)+" - "+Str(MapX)+" - "+Str(PixB-PixA)

			If SaveImage(#Image_Gadget,"c:\Screenshot.png",#PB_ImagePlugin_PNG)
				Webflag=#FlagMapSaved
			Else
				Webflag=#FlagMapPanik
			EndIf
		EndSelect

	Until Webflag>=#FlagMapSaved

	Debug ">>> "+Str(Webflag)

	DataSection
		#Q$=#DQUOTE$

		Webcontent:
		Data.s "<!DOCTYPE html PUBLIC "+#Q$+"-//W3C//DTD XHTML 1.0 Strict//EN"+#Q$
		Data.s #Q$+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"+#Q$+">"
		Data.s "<html	xmlns="+#Q$+"http://www.w3.org/1999/xhtml"+#Q$+">"
		Data.s "<head>"
		Data.s "<meta	http-equiv="+#Q$+"content-type"+#Q$+" content="+#Q$+"text/html; charset=utf-8"+#Q$+"/>"
		Data.s "<title>Forerunner Google Maps</title>"
		Data.s "<style	type="+#Q$+"text/css"+#Q$+">"
		Data.s "	body{margin:0px;}"
		Data.s "</style>"
		Data.s "<script	src="+#Q$+"http://maps.google.com/maps?file=api&v=2&key=****YOUR KEY****"+#Q$
		Data.s "	type="+#Q$+"text/javascript"+#Q$+"></script>"
		Data.s "<script	type="+#Q$+"text/javascript"+#Q$+">"
		Data.s "	//<![CDATA["
		Data.s ""
		Data.s "	function load() {"
		Data.s "	if (GBrowserIsCompatible()) {"
		Data.s "		var map = new GMap2(document.getElementById("+#Q$+"map"+#Q$+"));"
		Data.s "		map.setCenter(new GLatLng(#A,#B),#Z);"
		Data.s "		map.addOverlay(new GMarker(new GLatLng(#A,#B)));"
		Data.s "		map.hideControls();"
		Data.s "		map.disableDragging();"
		Data.s "		}"
		Data.s "	}"
		Data.s "	//]]>"
		Data.s "</script>"
		Data.s "</head>"
		Data.s "	<body onload="+#Q$+"load()"+#Q$+" onunload="+#Q$+"GUnload()"+#Q$+">"
		Data.s "		<div id="+#Q$+"map"+#Q$+" style="+#Q$+"width:#Xpx;height:#Ypx"+#Q$+"></div>"
		Data.s "	</body>"
		Data.s "</html>"
	EndDataSection

EndProcedure

GoogleMaps()
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

The program seen in the posting before works fine since a while, but the two questions from above haven't been solved until now - main problem is that I have to wait 15 seconds or so to be sure that the map will have been loaded :?

And now I have one addtional question, a (very crazy) proxy server has been installed here last week and I could not get the coding running to download the map through this proxy.
When I double click on the created htm file, the map will be displayed in the web browser, but my code fails :oops:

Who will be able to give me a hint?

Thanks for your help,
Michael
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> main problem is that I have to wait 15 seconds or so to be sure that the map will have been loaded

You probably can't get around that with your current way because the map tiles are loaded in the background so there is no "complete" event you can look for.

Try the Google Static Maps API, it lets you query a map as an image directly which sounds way easier. You could probably do that with the Http lib and get rid of the WebGadget alltogether:
http://code.google.com/apis/maps/docume ... taticmaps/

Btw, did you check the google terms of use wether what you are doing is actually allowed ? Note that there is also a limit on the requests per day (per user) which may get in the way of whatever you are trying to do.

You can also give OpenStreetMap a try. All map data there is licensed under CreativeCommons:
http://www.openstreetmap.org/
quidquid Latine dictum sit altum videtur
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

freak wrote: Try the Google Static Maps API [...]

You can also give OpenStreetMap a try[...]
Cool, thanks... :!:
I'll try to use one of these two things now - the usage restriction of Google Maps seems to be no problem, I'll just do it for myself - so 1000 calls per day is quite enough :)

Michael
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

as for the event you might want to try a DOMready() function in JS - i recall we had here some JS callback code which could give you an event back there.

Something along:

Code: Select all

window.addEvent('domready', function() {
  // call pb event func or return vals...
}

Maybe i am way off here - as i just read thru ! :)

Cheers,
Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Thanks for your hints!

Have done nearly all now - the only problem is, that Google (Static) Maps are using the GIF format :evil:

Michael
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

quidquid Latine dictum sit altum videtur
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

freak wrote:rtfm :P
Hmm, that's what I tried to do before but different file formats I found only when using google maps with java but not with the static maps :?
Maybe someone dont want that I'll get the right information, yout link brings me to a redirected page .../intl/de... which tells me, that the returned file is a gif formated picture :cry:

When using the "cache" option, I'll get the information about a format parameter, but for getting further information google redirects again and... :evil:

Can you tell me the correct parameter to get it in the jpg or png format?

Thanks,
Michael
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Post by Arctic Fox »

User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Sometimes I'm very close to the right thing, but moving around without getting in touch...

...thanks for giving me another push, now even me couldn't do something wrong :wink:

Michael
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

Here's another hint.

To make it a png image add this to the html:

Code: Select all

&format=png
to produce something like:

Code: Select all

http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=16&maptype=hybrid&size=512x512&format=png
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

I'm very interested in this, keep the samples coming, I'm watching this space!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply