Having UIWebView load Google Maps in Maps

Discussion in 'iOS Programming' started by RobbS, Apr 25, 2011.

  1. RobbS macrumors newbie

    Apr 21, 2011
    In one of my views I have an instance of UIWebView that loads a page with a Google Maps Form (Here). When submitting the form in Safari, the Maps application will open with directions. When opening inside of my UIWebView, it will display Google Maps Mobile directions.

    I've tried to change the User Agent of the browser so that it would think Safari was submitting the form, that didn't work. Then I tried Method Swizzling to change the user agent, which also didn't work.

    Any idea how to open Maps when submitting my form within UIWebView?
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    Do u want the view, or the actual lines of what to do? isn't there an API to call in XML/JSON which u could parse? No idea, just trying to put idea's in here. Since i'm kind off interested too
  3. RobbS thread starter macrumors newbie

    Apr 21, 2011
    Basically, I want the google maps link within my UIWebView to open in the Maps application as it would in Safari.

    User presses the button hbgView to bring up hbgViewController using this code:

            hbgViewController *hbgView=[[hbgViewController alloc] initWithNibName:nil bundle:nil];
            [self presentModalViewController:hbgView animated:YES];
    Then, I load the UIWebView session with the form using this code:

        - (void)viewDidLoad
            [super viewDidLoad];
            [svcWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"...com/mobile/map/hbg.html"]]];
    The form code of the hbg.html document is as follows:

        function redirect()
        var baseUrl = "http://maps.google.com/maps?saddr="
        var suffix = "&daddr=endaddress&hl=en";
        <form name="gmform" method="post" onsubmit="redirect()">
        <input type="text" id="url">
        <input type="submit" value="Go">

Share This Page