我有一个使用V3 API创建的Google地图,我希望使用StyledMapType应用自定义地图样式。但是,我发现在某些浏览器中,自定义样式JSON在URI中遇到字符限制,导致414错误(例如Leopard上的Firefox 7)。
缩短JSON可以解决问题,但有人可以就解决方案提出建议吗?
BTW,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%7Cp.s%3A20%7Cp.l%3A20%2Cs.t%3A17%7Cs.e%3Al%7Cp.h%3A%23ff8800%7Cp.l%3A6%7Cp.v%3Aon%7Cp.s%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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
答案 0 :(得分:0)
对我们有用的是将mapStyles对象缩短为1350个字符或更少 - 然后错误消失了。但这并不是理想的,而是我们能找到的唯一解决方案。