Having UIWebView load Google Maps in Maps

Discussion in 'iPhone/iPad Programming' started by RobbS, Apr 25, 2011.

  1. macrumors newbie

    Joined:
    Apr 21, 2011
    #1
    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. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    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. thread starter macrumors newbie

    Joined:
    Apr 21, 2011
    #3
    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:

    Code:
        -(IBAction)hbgButton:(id)sender{
            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:

    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:

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

Share This Page