Menu di ricerca

Buongiorno,

sono un nuovo utente della comunità OSM.

Di recente ho inserito nel mio sito web la mappa di OSM (sito svilupapto solo per la intranet non è pubblico).

Volevo capire se c’è la possibilità di inserire anche l’opzione di ricerca di un indirizzo sulla mappa, ovvero, il classico campo di testo dove inserisci un indirizzo e poi clicchi “Cerca”.

Grazie a tutti in anticipo!

Daniele

Take a look at Nominatim http://wiki.openstreetmap.org/wiki/Nominatim
The latitude and longitude coordinates are part of the result. But unfortunately, I cannot tell you how to integrate it into your website.

Che libreria hai usato? Leaflet? OpenLayers?
Ci sono diverse possibilità e plugin per integrare motori di geocoding. Esempio per leaflet http://leafletjs.com/plugins.html#geocoding

Ciao sabas88,

grazie milel intanto per la risposta e scusa il ritardo, io ho usato questo codice:

<script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>

<script type="text/javascript">
	// Start position for the map (hardcoded here for simplicity,
	// but maybe you want to get this from the URL params)
            var lat=46.08680;
            var lon=11.20168;
            var zoom=16;

	var map; //complex object of type OpenLayers.Map

	function init() {
		map = new OpenLayers.Map ("map", {
			controls:[
				new OpenLayers.Control.Navigation(),
				new OpenLayers.Control.PanZoomBar(),
                                    new OpenLayers.Control.ScaleLine(),
                                    new OpenLayers.Control.Permalink('permalink'),
                                    new OpenLayers.Control.MousePosition(),
				new OpenLayers.Control.LayerSwitcher(),
				new OpenLayers.Control.Attribution()],
			maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
			maxResolution: 156543.0399,
			numZoomLevels: 19,
			units: 'm',
			projection: new OpenLayers.Projection("EPSG:900913"),
			displayProjection: new OpenLayers.Projection("EPSG:4326")
		} );

		// Define the map layer
		// Here we use a predefined layer that will be kept up to date with URL changes
		layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
		map.addLayer(layerMapnik);
		layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
		map.addLayer(layerCycleMap);
		layerMarkers = new OpenLayers.Layer.Markers("Markers");
		map.addLayer(layerMarkers);
                    
		// Add the Layer with the GPX Track
		var lgpx = new OpenLayers.Layer.Vector("Descrizione del layer", {
			strategies: [new OpenLayers.Strategy.Fixed()],
			protocol: new OpenLayers.Protocol.HTTP({
				url: "traccia.gpx",
				format: new OpenLayers.Format.GPX()
			}),
			style: {strokeColor: "green", strokeWidth: 5, strokeOpacity: 0.5},
			projection: new OpenLayers.Projection("EPSG:4326")
		});
		map.addLayer(lgpx);

		var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
		map.setCenter(lonLat, zoom);

		var size = new OpenLayers.Size(21, 25);
		var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
		var icon = new OpenLayers.Icon('http://www.openstreetmap.org/openlayers/img/marker.png',size,offset);
		layerMarkers.addMarker(new OpenLayers.Marker(lonLat,icon));
	}
</script>

Quindi penso che stia usando OpenLayers, purtroppo sono all’inzio con questo mondo e quindi faccio ancora fatica a capire tutto.

Daniele

Ciao sabas88,

grazie milel intanto per la risposta e scusa il ritardo, io ho usato questo codice:

<script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>

<script type="text/javascript">
    // Start position for the map (hardcoded here for simplicity,
    // but maybe you want to get this from the URL params)
            var lat=46.08680;
            var lon=11.20168;
            var zoom=16;

    var map; //complex object of type OpenLayers.Map

    function init() {
        map = new OpenLayers.Map ("map", {
            controls:[
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                                    new OpenLayers.Control.ScaleLine(),
                                    new OpenLayers.Control.Permalink('permalink'),
                                    new OpenLayers.Control.MousePosition(),
                new OpenLayers.Control.LayerSwitcher(),
                new OpenLayers.Control.Attribution()],
            maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
            maxResolution: 156543.0399,
            numZoomLevels: 19,
            units: 'm',
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326")
        } );

        // Define the map layer
        // Here we use a predefined layer that will be kept up to date with URL changes
        layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
        map.addLayer(layerMapnik);
        layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
        map.addLayer(layerCycleMap);
        layerMarkers = new OpenLayers.Layer.Markers("Markers");
        map.addLayer(layerMarkers);
                   
        // Add the Layer with the GPX Track
        var lgpx = new OpenLayers.Layer.Vector("Descrizione del layer", {
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "traccia.gpx",
                format: new OpenLayers.Format.GPX()
            }),
            style: {strokeColor: "green", strokeWidth: 5, strokeOpacity: 0.5},
            projection: new OpenLayers.Projection("EPSG:4326")
        });
        map.addLayer(lgpx);

        var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
        map.setCenter(lonLat, zoom);

        var size = new OpenLayers.Size(21, 25);
        var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
        var icon = new OpenLayers.Icon('http://www.openstreetmap.org/openlayers/img/marker.png',size,offset);
        layerMarkers.addMarker(new OpenLayers.Marker(lonLat,icon));
    }
</script>

Quindi penso che stia usando OpenLayers, purtroppo sono all’inzio con questo mondo e quindi faccio ancora fatica a capire tutto.

Daniele