【问题标题】:The Google Maps Embed API must be used in an iframe in UIWebview必须在 UIWebview 的 iframe 中使用 Google Maps Embed API
【发布时间】:2014-05-23 19:09:45
【问题描述】:

我正在尝试在 UIWebview 上加载谷歌地图并调用 http://maps.google.com/?saddr=22.718019,75.884460&daddr=33.391823,-111.961731&zoom=10&output=embed,但它显示错误“Google Maps Embed API 必须在 UIWebview 的 iFrame 中使用”它之前可以工作,但现在无法正常工作。我正在尝试像这样在 iframe 中加载这个 URL

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。

请帮忙.. 谢谢!

【问题讨论】:

    标签: ios objective-c google-maps iframe


    【解决方案1】:

    您的 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];
    
    
    }
    

    【讨论】:

      【解决方案2】:

      是的,我认为 Google 在 2014 年 4 月停止了使用此参数“output=embed”的调用。有关使用 IFRAME 方法的解决方法,请参阅 https://forums.embarcadero.com/message.jspa?messageID=642868

      史蒂夫

      【讨论】:

      • 请在此处包含答案的主要部分,并使用链接作为参考。
      猜你喜欢
      • 1970-01-01
      • 2017-02-14
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多