ios – 必须在UIWebview中的iframe中使用Google Maps Embed API

我正在尝试在UIWebview上加载谷歌地图并调用
http://maps.google.com/?saddr=22.718019,75.884460&daddr=33.391823,-111.961731&zoom=10&output=embed,但它显示错误“必须在UIWebview中的iFrame中使用谷歌地图嵌入API”它之前正在工作它不工作.我正在尝试加载此URL 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.

请帮忙..
谢谢!

最佳答案 你的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];


}
点赞