4

How can I use an OpenStreetMap service (an online server) to programmatically fetch a street map image, as a downloadable image file, from just a latitude–longitude value and zoom factor?

My application has a set of latitude–longitude values, and for each one I need an OpenStreetMap diagram – an image, not a web page – showing the location with a pin on the street map. The image needs to be a single SVG or PNG for further offline processing.

How can I programmatically construct a URL (at e.g. http://www.openstreetmap.org/ or http://www.opencyclemap.org/ or a similar service), parameterised by the latitude–longitude value and perhaps a zoom factor, that will return just the map image I'm interested in, including a pin at the location specified?

bignose
  • 30,281
  • 14
  • 77
  • 110

2 Answers2

6

In order to fetch a particular tile, you have to provide the zoom, the x coordinate, and the y coordinate to the URL

Here's the URL for OpenStreetMap

http://[abc].tile.openstreetmap.org/zoom/x/y.png 

The [abc] means that you use a or b or c. These are three different subdomains on the OpenStreetMap server.

Here's a tile I pulled down using zoom 11, x = 510, y = 844

enter image description here

You have to convert latitude and longitude to an (x, y) coordinate. See this answer for a more complete explanation of tile sets and links to the conversion code.

You are limited in the number of tiles that you can retrieve from the OpenStreetMap servers. Be sure to cache the tiles that you retrieve.

Community
  • 1
  • 1
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
0

Sounds like you want to access via WMS (web mapping service). You can find a list of mirrors for OSM WMS here. I'm not sure of your end use for it, but there are several links on this wiki page to projects that can consume WMS. I've used GeoServer in some previous GIS projects and really liked it (don't know if this is your use-case though).

sevensevens
  • 1,703
  • 16
  • 27