Vamshi Krishna Vamshi Krishna - 5 months ago 11
iOS Question

Maps not being shown in webview- iOS

I have a button in my view. On clicking it leads to a webview in which I want to show the maps. The code I am using is:

- (void)viewWillAppear:(BOOL)animated{
NSString *url = [@"http://maps.apple.com/?q=" stringByAppendingString:self.address];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
NSURLRequest *metricsRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
_webViewForLocation.delegate = self;
[_webViewForLocation loadRequest:metricsRequest];
NSLog(@"Maps String: %@", url);
}


But the webview is blank. HOw do I show maps in it?

Answer

try

- (void)viewDidLoad
{
[super viewDidLoad];

[_webViewForLocation loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/?q=bangalore"]]]];  // here pass your string


- (void)webViewDidStartLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{

 }



- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

the output is

enter image description here

refers this document,

Comments