2

我在客户端编写此代码并发送到服务器以发送电子邮件。在该电子邮件中,图像显示为损坏的图像我想在谷歌静态地图上绘制路径。这是我使用的代码。

<img src = "http://maps.googleapis.com/maps/api/staticmap?size=400x400&path=weight:3%7Ccolor:orange%7Cenc:'+polyline+'" />

我以这种方式创建的折线

 var polyline;
var points = new Array();
for(var i=0; i<googleRoute.getVertexCount(); i++)
{
    points[i] = new GLatLng(googleRoute.getVertex(i).lng(),googleRoute.getVertex(i).lat());
}
polyline = new GPolyline(points, '#ff0000', 5, 0.7);  

当我使用此代码时,它不会出现图像。我在客户端编写此代码并发送到服务器以发送电子邮件。在该电子邮件中,图像显示为损坏的图像,我的代码有什么问题吗?

4

2 回答 2

1

当两个城市之间的距离增加时,折线变量将包含很多 Glatlang 值。所以它会导致超出 url 字符限制(什么是 URL 的字符限制)。我们不能使用 ajax 请求发送超过字符限制的长 url。这就是为什么我得到那个破碎的形象。作为解决方案,我通过使用跳过值增加 for 循环来忽略中间 Glatlang 值。因此,折线可以接受缩小地图。

于 2012-02-22T14:33:20.497 回答
0

如果您有一系列点,您可以简单地执行以下操作:

$points = array('53.061969559518,-3.1661187796875', '52.647368106972,-2.6806604056641');
$pointsUrl = "";
for($i=0; $i<count($points); $i++) {
   $pointsUrl .= '%7C'.$points[$i];
}
echo '<img src="http://maps.googleapis.com/maps/api/staticmap?path=color:0x0000ff%7Cweight:5'.$pointsUrl.'&size=270x256&maptype=roadmap&sensor=false" />';  
于 2012-02-22T11:36:41.330 回答