2

I have a simple code to display a map of Openstreetmaps via Openlayers based on latitude/longitude:

map = new OpenLayers.Map('#map');
var mapnik         = new OpenLayers.Layer.OSM();
var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(geo.lng,geo.lat).transform( fromProjection, toProjection);
var zoom = 14; 

map.addLayer(mapnik);
map.setCenter(position, zoom);

var markers = new OpenLayers.Layer.Markers( "Markers" );        
markers.addMarker(new OpenLayers.Marker(position));
map.addLayer(markers);

What i now would like to do is displaying a map not based on lat/lng but just with an address, perhaps via OpenStreetMap nominatim. So i have the code above and an address string e.g. "country, state, city", without street/-nr. How do i point the map to that city?

scai
  • 20,297
  • 4
  • 56
  • 72
Alex Schneider
  • 335
  • 1
  • 6
  • 17

2 Answers2

2

You were almost there, take a look at the country,city and format parameters:

http://nominatim.openstreetmap.org/search.php?country=England&city=London&format=json

http://wiki.openstreetmap.org/wiki/Nominatim

pkExec
  • 1,752
  • 1
  • 20
  • 39
0

You need a Gazetteer for this, which is basically a dictionary filled with place names and location identifiers. There are several ways to use GeoNames for this purpose or other GeoCoders. Here is an example for Openlayers and OSM using OpenRouteService: http://openlayers.org/dev/examples/openls.html

Martin
  • 896
  • 1
  • 7
  • 22
  • is there no way to just get the lat/lng from a search like this: http://nominatim.openstreetmap.org/search.php?q=England+London ... afaik there is some way to get the response as json, maybe there is lat/lng included? – Alex Schneider Dec 10 '12 at 15:14