I'd like to have a script (bash) to generate an img (gif, jpg, etc.) of a (openstreetmap or googlemap) map given a location, like this:
$ gen开发者_开发技巧map.sh 45.5 9.5
(parameters are lat & long)
or:
$ genmap.sh 45.5 9.5 12
(parameters are lat & long and zoom)
etc. etc.
can you point me to something on the net?
thank you
Google Maps provides an API you can use for generating maps. See their documentation on the API for static maps.
- Latitudes and Longitudes
- Zoom Levels
A basic example script which accept lat as first, long as second and an optional zoom as third. It outputs an PNG image with a filename like lat-long-zoom-width-height.png
and echo's the filename:
#!/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"
You might need to add additional tweaks to check the error response.
OpenStreetMap has an exporting API, which you could use with, say, wget:
http://tile.openstreetmap.org/cgi-bin/export?bbox=-3.296,58.906,-2.781,59.139&scale=435000&format=png
Currently though, it gives over-load errors.
精彩评论