Google Maps API 样式的地图类型 414 错误

发布于 2024-12-10 21:38:05 字数 3378 浏览 0 评论 0原文

我有一个使用 V3 API 创建的 Google 地图,我希望使用 StyledMapType 应用自定义地图样式。但是,我发现在某些浏览器中,自定义样式 JSON 达到了 URI 中的字符限制,导致 414 错误(例如 Leopard 上的 Firefox 7)。

缩短 JSON 可以解决问题,但是有人可以建议解决方案吗?

顺便说一句,JSON 已经被空格压缩了!

谢谢

这是一个代码示例。我们必须将 mapStyles 保持在大约 1705 个字符以内,否则会出现 414 错误。事实上,当我们放大时,错误仍然出现,我已经缩短到1350个字符来停止错误。

var mapStyles=[{featureType:"road",elementType:"geometry",stylers:[{lightness:100},{visibility:"on"}]},{featureType:"road",elementType:"labels",stylers:[{hue:"#ff7700"},{lightness:12},{saturation:-38},{visibility:"on"}]}];

gMapStyled = new google.maps.StyledMapType(mapStyles, {name: 'Store Locator'});

gMap = new google.maps.Map($('#map-canvas').get(0), {
                disableDefaultUI: true,
                zoom: 7,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: new google.maps.LatLng('5.7908968128719565','19.6875')
            });
gMap.mapTypes.set('storelocator', gMapStyled);
gMap.setMapTypeId('storelocator'); 

这是 414 错误的示例...很长!

NetworkError: 414 Request-URI Too Large - http://mt0.googleapis.com/mapslt/ft?hl=en&lyrs=m%40162244780%7Cs.t%3A3%7Cs.e%3Ag%7Cp.l%3A100%7Cp.v%3Aon%2Cs.t%3A3%7Cs.e%3Al%7Cp.h%3A%23ff7700%7Cp.l%3A12%7Cp.s%3A-38%7Cp.v%3Aon%2Cs.t%3A40%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.s%3A-77%7Cp.l%3A41%2Cs.t%3A4%7Cp.v%3Aoff%2Cs.t%3A21%7Cp.v%3Aoff%2Cs.t%3A18%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.h%3A%23ffaa00%7Cp.s%3A32%2Cs.t%3A17%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.h%3A%23ff8800%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A-38%7Cp.v%3Aon%2Cs.t%3A40%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.s%3A-77%7Cp.l%3A41%2Cs.t%3A4%7Cp.v%3Aoff%2Cs.t%3A21%7Cp.v%3Aoff%2Cs.t%3A18%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.h%3A%23ffaa00%7Cp.s%3A32%2Cs.t%3A17%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.h%3A%23ff8800%7Cp.s%3A20%7Cp.l%3A20%2Cs.t%3A17%7Cs.e%3Al%7Cp.h%3A%23ff8800%7Cp.l%3A6%7Cp.v%3Aon%7Cp.s%3A20%2Cs.t%3A18%7Cs.e%3Al%7Cp.v%3Aon%7Cp.s%3A-100%2Cs.t%3A19%7Cs.e%3Al%7Cp.s%3A-100%7Cp.v%3Aon%7Cp.l%3A31%2Cs.t%3A81%7Cs.e%3Ag%7Cp.g%3A1%7Cp.h%3A%23ffcc00%7Cp.v%3Aon%7Cp.l%3A45%7Cp.s%3A-82%2Cs.t%3A82%7Cs.e%3Ag%7Cp.h%3A%23ffcc00%7Cp.l%3A-2%7Cp.v%3Asimplified%7Cp.s%3A-5%2Cs.t%3A6%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.s%3A-79%2Cs.t%3A1059%7Cp.v%3Aon%7Cp.s%3A-99%2Cs.t%3A40%7Cs.e%3Al%7Cp.v%3Asimplified%7Cp.s%3A-6%2Cs.t%3A37%7Cs.e%3Ag%7Cp.v%3Aoff&callback=_xdc_._5mgxkk&token=13463

I have a Google Map created with V3 API, and I wish to apply a custom map styles using StyledMapType. However, I find in some browsers the custom style JSON is hitting a character limit in the URI, resulting in a 414 error (such as Firefox 7 on Leopard).

Shortening the JSON solves the problem, but can anybody advise on a solution?

BTW, the JSON is already whitespace compressed!

Thanks

Here is a code example. We have to keep mapStyles within about 1705 characters otherwise the 414 error occurs. Actually, the error still occurs when we zoom in, and I have shorten to 1350 characters to stop the error.

var mapStyles=[{featureType:"road",elementType:"geometry",stylers:[{lightness:100},{visibility:"on"}]},{featureType:"road",elementType:"labels",stylers:[{hue:"#ff7700"},{lightness:12},{saturation:-38},{visibility:"on"}]}];

gMapStyled = new google.maps.StyledMapType(mapStyles, {name: 'Store Locator'});

gMap = new google.maps.Map($('#map-canvas').get(0), {
                disableDefaultUI: true,
                zoom: 7,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: new google.maps.LatLng('5.7908968128719565','19.6875')
            });
gMap.mapTypes.set('storelocator', gMapStyled);
gMap.setMapTypeId('storelocator'); 

Here is an example of the 414 error...very long!

NetworkError: 414 Request-URI Too Large - http://mt0.googleapis.com/mapslt/ft?hl=en&lyrs=m%40162244780%7Cs.t%3A3%7Cs.e%3Ag%7Cp.l%3A100%7Cp.v%3Aon%2Cs.t%3A3%7Cs.e%3Al%7Cp.h%3A%23ff7700%7Cp.l%3A12%7Cp.s%3A-38%7Cp.v%3Aon%2Cs.t%3A40%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.s%3A-77%7Cp.l%3A41%2Cs.t%3A4%7Cp.v%3Aoff%2Cs.t%3A21%7Cp.v%3Aoff%2Cs.t%3A18%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.h%3A%23ffaa00%7Cp.s%3A32%2Cs.t%3A17%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.h%3A%23ff8800%7Cp.s%3A20%7Cp.l%3A20%2Cs.t%3A17%7Cs.e%3Al%7Cp.h%3A%23ff8800%7Cp.l%3A6%7Cp.v%3Aon%7Cp.s%3A20%2Cs.t%3A18%7Cs.e%3Al%7Cp.v%3Aon%7Cp.s%3A-100%2Cs.t%3A19%7Cs.e%3Al%7Cp.s%3A-100%7Cp.v%3Aon%7Cp.l%3A31%2Cs.t%3A81%7Cs.e%3Ag%7Cp.g%3A1%7Cp.h%3A%23ffcc00%7Cp.v%3Aon%7Cp.l%3A45%7Cp.s%3A-82%2Cs.t%3A82%7Cs.e%3Ag%7Cp.h%3A%23ffcc00%7Cp.l%3A-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s.t%3A18%7Cs.e%3Al%7Cp.v%3Aon%7Cp.s%3A-100%2Cs.t%3A19%7Cs.e%3Al%7Cp.s%3A-100%7Cp.v%3Aon%7Cp.l%3A31%2Cs.t%3A81%7Cs.e%3Ag%7Cp.g%3A1%7Cp.h%3A%23ffcc00%7Cp.v%3Aon%7Cp.l%3A45%7Cp.s%3A-82%2Cs.t%3A82%7Cs.e%3Ag%7Cp.h%3A%23ffcc00%7Cp.l%3A-2%7Cp.v%3Asimplified%7Cp.s%3A-5%2Cs.t%3A6%7Cs.e%3Ag%7Cp.v%3Aon%7Cp.s%3A-79%2Cs.t%3A1059%7Cp.v%3Aon%7Cp.s%3A-99%2Cs.t%3A40%7Cs.e%3Al%7Cp.v%3Asimplified%7Cp.s%3A-6%2Cs.t%3A37%7Cs.e%3Ag%7Cp.v%3Aoff&callback=_xdc_._5mgxkk&token=13463

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那小子欠揍 2024-12-17 21:38:05

对我们有用的方法是将 mapStyles 对象缩短为 1350 个字符或更少 - 然后错误就消失了。但这并不意味着理想,而是我们能找到的唯一解决方案。

What worked for us was to shorten the mapStyles object at 1350 characters or less - then the error disappeared. But no means ideal but the only solution we could find.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文