-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhancement: drop marker at geocoded location #7
Comments
it shouldn't be too difficult - modify the callback function. Nominatum returns a lon lat position which is accessable by
to set a marker should work by
but it doesn't - seams like my break in JS develloping was to long |
Hm. I tried a couple variations on that and couldn't get it to work. I'll keep trying. Thanks for the idea! |
Here's a solution I came up with. You could use a standard marker instead of the Leaflet Awesome Markers plugin shown in the example. var searchBounds;
var addressSearchResults;
// OSM Geocoder
osmGeocoder = new L.Control.OSMGeocoder({
collapsed: false,
position: 'topright',
text: 'Search',
placeholder: 'Enter address',
bounds: searchBounds,
callback: function(results) {
// add a message on the screen about not finding an address (future step)
if (results.length == 0) {
console.log("ERROR: didn't find a result");
}
// clear previous geocode results
addressSearchResults.clearLayers();
// create icon for result
var addressSearchIcon = L.AwesomeMarkers.icon({
icon: 'map',
prefix: 'fa',
markerColor: 'orange',
iconColor: '#fff'
});
// get coordinates for result
var coords = L.latLng(results[0].lat,results[0].lon);
// create a marker for result
var marker = L.marker(coords, {
icon: addressSearchIcon
});
// add result object to map and zoom to
addressSearchResults.addLayer(marker);
this._map.addLayer(marker).setView(coords,17);
// open pop-up for location
var popup = L.popup({closeOnClick: true}).setLatLng(coords).setContent(results[0].display_name).openOn(map);
}
}).addTo(map); |
Try this code it's working with marker
</script>` |
I'm working on a project where users will want to compare their address against a polygon layer. Once they find their address, they'll want to zoom out and pan to look at the polygon boundaries. How hard would it be to drop a pin at the location returned by the geocoder?
The text was updated successfully, but these errors were encountered: