Alex Schneider
Alex Schneider

Reputation: 355

nominatim with Openlayers

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?

Upvotes: 2

Views: 3481

Answers (2)

pkExec
pkExec

Reputation: 2086

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

Upvotes: 2

Martin
Martin

Reputation: 896

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

Upvotes: 0

Related Questions