我的应用程序使用 Google Maps v3 创建 map ,上面有很多标记和集群,并且工作正常。
同一张 map 我也必须在另一个浏览器窗口中显示,但由于某些原因它不能(只得到空 map ,上面没有标记/簇)。我在 Firebug 中检查了错误,并且有一条消息:
NetworkError: 414 Request-URI Too Large
所以 - 相同的 map ,在第一个浏览器窗口中正常,在第二个窗口中则不行。
只是说我通过发送关于我在第一张 map 上的每个标记的参数来打开第二张 map (在第二个窗口中),所以 URL 很长(2700 个字符)。
有什么办法可以解决吗?长url字符串有问题吗?
你能帮我解决这个问题吗?
最佳答案
问题出在您生成的 URL 中。 Google 为传递的 URL 指定了 2000 个字符的限制,我们应该坚持下去。
我通过在将 URL 传递给 Google 之前生成 URL 的哈希值解决了我的应用程序中的问题。
1) 创建一个数据库表来存储您的哈希值。列可以是散列、参数、时间戳。您可以通过删除早于特定时间的哈希来改进您的代码,使表保持小而快。
2) 创建代码 (my_google_map_helper/get_hash) 以生成要传递给 Google 的散列并将其粘贴在某处。我正在使用 PHP,所以我的代码是:
// generate my hash
$hash = sha1(serialize($_GET));
// run an insert ignore into my hashes' table
// get the hash where the hash is $hash
// print my hash
3) 创建一个代码 (get_kml) 以从给定的哈希中检索保存到数据库中的参数
if(isset($_GET['hash'])):
// select params from my hash table where hash = $_GET['hash']
// unserialize the saved params
// generate and return my KML file
endif;
4) 更改您的 JavaScript,使其在调用 Google 函数之前生成哈希:
$.get('my_google_map_helper/get_hash?' + MY_LONG_PARAMS_LIST, true)
, function(hash){
Polygons = new google.maps.KmlLayer(
{url:'http://my_url/get_kml?hash=' + hash , map:MAP}
);
}
);
玩得开心!
关于google-maps - 网络错误 : 414 Request-URI Too Large with Google Maps v3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9286082/