Google Maps Platform拒绝了您的请求.无效的"pb"参数 [英] Google Maps Platform rejected your request. Invalid 'pb' parameter

查看:282
本文介绍了Google Maps Platform拒绝了您的请求.无效的"pb"参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网络视图中显示Google地图,但这是在说

I am trying to show Google map in webview, but it is saying

Google Maps Platform拒绝了您的请求.无效的请求.无效的"pb"参数.

Google Maps Platform rejected your request. Invalid request. Invalid 'pb' parameter.

但是当我在网络浏览器上渲染相同的iframe时,它运行良好

But when I am rendering the same iframe on web browser, it is working perfectly

这是我要在网络视图中呈现的内容,这是存储在变量 iframeData

here is what I am trying to render in webview, this is the string stored in variable iframeData

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
    <body>
        <iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d14988.154038971099!2d57.510438!3d-20.090677!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xc479c0ed4774c8e7!2sThe+Westin+Turtle+Bay+Resort+%26+Spa%2C+Mauritius!5e0!3m2!1sen!2smu!4v1513055435928" width="340.0" height="250" frameborder="0" style="border:0" allowfullscreen></iframe>
    </body>
</html>

这是我的Android代码,用于将此iframe呈现到webview

And this is my Android code to render this iframe into webview

String iframeData = //look above

WebView webViewMap = (WebView) rootView.findViewById(R.id.webViewMap);
WebSettings settings = webViewMap.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(false);
settings.setUseWideViewPort(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    settings.setAllowUniversalAccessFromFileURLs(true);
}
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webViewMap.loadData(iframeData, "text/html", null);

推荐答案

示例中iframe内的URL看起来像是从Google Maps网站上的共享位置获得的链接.通常,不应将此网址视为Google Maps Platform产品.但是,由于某些原因,Google在WebView组件中将其视为Google Maps Platform.

The URL inside iframe in your example looks like a link obtained from share location on Google Maps web site. Typically this URL shouldn't be treated as Google Maps Platform product. However, for some reason Google treats it as Google Maps Platform in the WebView component.

我认为这是Google的错误.

I think this is a bug on Google side.

解决方法是使用 Google Maps Embed API .在这种情况下,您将拥有正确的Google Maps Platform链接,它应该可以正常工作.请注意,您需要有效的API密钥才能使用Google Maps Embed API.

The workaround is replacing URL for share with URL from Google Maps Embed API. In this case you will have correct Google Maps Platform link and it should work as expected. Note that you will need a valid API key in order to use Google Maps Embed API.

代码段为:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
    <body>
      <iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=The+Westin+Turtle+Bay+Resort+%26+Spa%2C+Mauritius&key=AIzaSyDztlrk_3CnzGHo7CFvLFqE_2bUKEq1JEU" allowfullscreen></iframe>
    </body>
</html>

您应该用我的API密钥替换.

You should replace my API key with yours.

我希望这会有所帮助!

这篇关于Google Maps Platform拒绝了您的请求.无效的"pb"参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆