用于生成地图的shell脚本

时间:2011-04-12 11:49:19

标签: shell map

我希望有一个脚本(bash)来生成给定位置的(openstreetmap或googlemap)地图的img(gif,jpg等),如下所示:

$ genmap.sh 45.5 9.5

(参数是lat& long)

或:

$ genmap.sh 45.5 9.5 12

(参数是lat& long和zoom)

等。等

你可以指点网上的东西吗?

谢谢

2 个答案:

答案 0 :(得分:2)

Google地图提供了一个可用于生成地图的API。请参阅API for static maps上的文档。

一个基本的示例脚本,它接受lat作为第一个,long为第二个,可选缩放为第三个。它输出一个PNG图像,其文件名为lat-long-zoom-width-height.png,echo是文件名:

#!/bin/bash
width=400
height=400
lat="$1"
long="$2"
zoom=12
if [ -n "$3" ]; then
    zoom="$3"
fi
filename="$lat-$long-$zoom-${width}x$height.png"
wget "http://maps.google.com/maps/api/staticmap?center=$lat,$long&zoom=$zoom&size=${width}x${height}&sensor=false" -O "$filename"
# small error checking
if [ $? -ne 0 ]; then
    echo "An error occured" >&2
    exit 1
fi
echo "$filename"

您可能需要添加其他调整来检查错误响应。

答案 1 :(得分:1)

OpenStreetMap有一个导出API,你可以使用wget:

http://tile.openstreetmap.org/cgi-bin/export?bbox=-3.296,58.906,-2.781,59.139&scale=435000&format=png

目前,它会出现过载错误。