我有一个简单的代码来通过基于纬度/经度的 Openlayers 显示 Openstreetmaps 的地图:
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);
我现在想做的是显示一张不基于纬度/经度的地图,而只是显示一个地址,也许是通过 OpenStreetMap nominatim。所以我有上面的代码和一个地址字符串,例如“国家、州、城市”,没有街道/-nr。我如何将地图指向那个城市?