webview not loading url with parameters

I am writing a simple app to help me geocode some addresses to use on my tomtom navigation device. I have the app almost working but the url to load a static map will not load in the webview object. I have included the code I use but cannot include my API key, so the url below will not load. In my app I can load “http://www.google.com” , So I know the app is working and assume I need to encode the more complex url somehow. The url that is throwing an error does load in Safari. The error is:

The variable URLWithString is not defined. (-2753)

The URL minus my api code is: http://maps.google.com/maps/api/staticmap?size=306x493&maptype=hybrid&sensor=false&markers=color:blue|label:S|47.2675853,-122.5846934|47.329264,-122.5801293&key = MYAPI KEY

set mapURL to "http://maps.google.com/maps/api/staticmap?size=306x493&maptype=" & maptype & "&sensor=false&markers=color:blue|label:S" & googleMarkers & "&key = " & queryKey

loadPage from mapURL
on loadPage from theURL
	set URLWithString to call method "URLWithString:" of class "NSURL" with parameter theURL
	set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
	tell window "main"
		set mainFrame to call method "mainFrame" of object (view "browser")
	end tell
	call method "loadRequest:" of mainFrame with parameter requestWithURL
end loadPage

Hi,

try


on loadPage from theURL
	set escapedString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30) -- 30 = MacRoman, 4 = UTF8
	set URLWithString to call method "URLWithString:" of class "NSURL" with parameter escapedString
.

Thank you once again StefanK, that did the trick! So what happened? What exactly was that call and where can I learn more about it?

Thank you,
Todd

the method encodes non-alphanumeric characters into the form %[ascii number], e.g. space is %20

For reference: stringByAddingPercentEscapesUsingEncoding: