在谷歌静态地图上绘制路径

时间:2011-08-03 11:55:48

标签: google-static-maps

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

<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);  

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

2 个答案:

答案 0 :(得分:1)

当两个城市之间的距离增长时,折线变量将包含许多Glatlang值。所以它导致超过网址字符限制(What is the character limit on URL)。  我们不能使用ajax请求发送超过charcter限制的长URL。这就是我得到破碎图像的原因。 作为解决方案,我通过使用跳过值递增for循环来忽略中间Glatlang值。因此,可以接受折线以缩小地图。

答案 1 :(得分: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" />';  
相关问题