我有一组具有纬度和经度值的点,我正在尝试使用以下格式创建一个字符串,以便使用Gmaps API:
LatitudeX,LongitudeX|LatitudeY,LongitudeY
Run Code Online (Sandbox Code Playgroud)
最终的字符串将使用未知数量的lat long对构建.
我以前的经验是使用PHP,虽然我已经设法得到一些工作,但它看起来有点笨拙,我想知道是否有更多'pythonic'方式来实现结果.
这是我到目前为止所拥有的:
waypoints = ''
for point in points:
waypoints = waypoints+"%s,%s" % (point.latitude, point.longitude)+"|"
waypoints = waypoints[:-1]
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏
谢谢
Mar*_*ers 10
用途str.join:
waypoints = '|'.join("{0},{1}".format(p.latitude, p.longitude) for p in points)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3840 次 |
| 最近记录: |