Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.3: Integrate maporama.com maps in Address Book' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Integrate maporama.com maps in Address Book
Authored by: vondrix on Jan 07, '04 09:05:38PM
Here are some more modifications. (based on aranors script). They both show only the map (1000x1000). The first script shows it directly in Safari, the second one first downloads the image to your desktop, and opens it in preview. (note that it may take a few seconds, and doesn't really show any progress information) Show in browser:


using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for aPerson with anAddress
		return "Show map (maporama)"
	end action title
	
	on should enable action for aPerson with anAddress
		return true
	end should enable action
	
	on perform action for aPerson with anAddress
		set imageUrl to my getMap(street of anAddress, zip of anAddress, city of anAddress, state of anAddress, country code of anAddress)
		tell application "Safari"
			activate
			open location imageUrl
		end tell
	end perform action
end using terms from

on getMap(street, zip, city, state, country)
	-- Create GET string for maporama
	-- COUNTRYCODE _XgoGCAddress Zip State _XgoGCTownName
	if country is missing value then
		set countryCode to "US"
	else
		set countryCode to toUpper(country)
	end if
	set theUrl to "http://www.maporama.com/share/map.asp?" & "COUNTRYCODE=" & encode_text(countryCode) & "&_XgoGCAddress=" & encode_text(street) & "&Zip=" & encode_text(zip) & "&State=" & encode_text(state) & "&_XgoGCTownName=" & encode_text(city)
	return image_url(theUrl)
end getMap

-- this sub-routine is used to get the url for the 1000x1000 image, given the url to the normal maporama page map
on image_url(textUrl)
	return do shell script "curl -s '" & textUrl & "' | awk -F'image.asp' '{print $2}' |sed -e 's/amp;//g' | sed -e 's/[23][67][03]/1000/g' | awk -F'\"' '/XMLOUT/ {print \"http://www.maporama.com/image.asp\" $1}'"
end image_url

-- this sub-routine is used to encode text 
on encode_text(this_text)
	return do shell script "php -r 'echo urlencode(\"" & this_text & "\");'"
end encode_text

-- this sub-routine uppercases a string
on toUpper(this_text)
	return do shell script "php -r 'echo strtoupper(\"" & this_text & "\");'"
end toUpper
Show in preview.app


using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for aPerson with anAddress
		return "Download map to desktop (maporama)"
	end action title
	
	on should enable action for aPerson with anAddress
		return true
	end should enable action
	
	on perform action for aPerson with anAddress
		set imageUrl to my getMap(street of anAddress, zip of anAddress, city of anAddress, state of anAddress, country code of anAddress)
		
		set outputFileName to ((path to desktop) as string) & "Map of " & name of aPerson & ".gif"
		tell application "URL Access Scripting"
			download imageUrl to outputFileName replacing yes with progress
		end tell
		tell application "Finder" to open file outputFileName
		
	end perform action
end using terms from

on getMap(street, zip, city, state, country)
	-- Create GET string for maporama
	-- COUNTRYCODE _XgoGCAddress Zip State _XgoGCTownName
	if country is missing value then
		set countryCode to "US"
	else
		set countryCode to toUpper(country)
	end if
	set theUrl to "http://www.maporama.com/share/map.asp?" & "COUNTRYCODE=" & encode_text(countryCode) & "&_XgoGCAddress=" & encode_text(street) & "&Zip=" & encode_text(zip) & "&State=" & encode_text(state) & "&_XgoGCTownName=" & encode_text(city)
	return image_url(theUrl)
end getMap

-- this sub-routine is used to get the url for the 1000x1000 image, given the url to the normal maporama page map
on image_url(textUrl)
	return do shell script "curl -s '" & textUrl & "' | awk -F'image.asp' '{print $2}' |sed -e 's/amp;//g' | sed -e 's/[23][67][03]/1000/g' | awk -F'\"' '/XMLOUT/ {print \"http://www.maporama.com/image.asp\" $1}'"
end image_url

-- this sub-routine is used to encode text 
on encode_text(this_text)
	return do shell script "php -r 'echo urlencode(\"" & this_text & "\");'"
end encode_text

-- this sub-routine uppercases a string
on toUpper(this_text)
	return do shell script "php -r 'echo strtoupper(\"" & this_text & "\");'"
end toUpper


[ Reply to This | # ]
10.3: Integrate maporama.com maps in Address Book
Authored by: luckyluke666 on Jan 08, '04 04:19:02AM

on my system (10.3.2) this script does not compile:
on perform action for aPerson with anAddress

Syntax Error
Expected end of line but found identifier

("aPerson" is highlighted)

---
Luc Bourhis



[ Reply to This | # ]