2014-04-10 45 views
4

我試圖加載UIWebview上的谷歌地圖並呼籲http://maps.google.com/?saddr=22.718019,75.884460&daddr=33.391823,-111.961731&zoom=10&output=embed,但它顯示錯誤「谷歌地圖嵌入API必須在UIWebview中的iFrame中使用」這是工作前,現在它不是working.I我試圖在iframe中加載這個URL這樣谷歌地圖嵌入API必須用於UIWebview中的iframe

NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f&zoom=10",[self.startLat floatValue], [self.startLon floatValue], [self.destLat floatValue],[self.destLon floatValue]];  
     NSString *embedHTML = [NSString stringWithFormat:@"<iframe width=\"300\" height=\"250\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>" ,googleMapsURLString]; 
NSString *html = [NSString stringWithFormat:embedHTML]; 

,但它不工作,並給予一定的WebKitError。

請幫忙.. 謝謝!

回答

2

您的iFrame實施爲我工作。這裏是我的方法:

-(void)showMapOnWebview:(UIWebView*)webview withUrl:(NSString*)urlAddress 
{ 

    //Create a URL object. 
    NSURL *url = [NSURL URLWithString:[urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 


    NSString *embedHTML = [NSString stringWithFormat:@"<html><head><title>.</title><style>body,html,iframe{margin:0;padding:0;}</style></head><body><iframe width=\"%f\" height=\"%f\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe></body></html>" ,webview.frame.size.width,webview.frame.size.height, url]; 

    [webview loadHTMLString:embedHTML baseURL:url]; 


}