Skip to content

Instantly share code, notes, and snippets.

@jacobandresen
Created February 20, 2011 17:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobandresen/836127 to your computer and use it in GitHub Desktop.
Save jacobandresen/836127 to your computer and use it in GitHub Desktop.
nonimatim openlayers jquery example
$(function() {
var geoCodeURL = "http://nominatim.openstreetmap.org/search";
var map = new OpenLayers.Map({ div: "map" });
var osm = new OpenLayers.Layer.OSM();
map.addLayers([osm]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(
new OpenLayers.LonLat( 9.2134, 55.3028).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10);
$("#address").autocomplete({
source: function ( request, response ) {
$.ajax({
url: geoCodeURL,
data: {
format: "json",
q: request.term
},
success: function ( data ) {
response ( $.map( data, function( item ) {
return {
label: item.display_name,
value: item.display_name,
lat: item.lat,
lon: item.lon
}}));
}
})
},
minLength: 2,
delay: 200,
select: function ( event, ui ) {
map.setCenter(
new OpenLayers.LonLat( ui.item.lon, ui.item.lat).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 13);
},
open: function () {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top");
},
close: function () {
$( this ).removeClass( "ui-corner-top").addClass("ui-corner-all");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment