Mapquest reverse geocoding from Leaflet map click
by Alex Azuero
HTML
<script src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.css">
<script src="http://www.mapquestapi.com/sdk/leaflet/v2.s/mq-map.js?key=sv99PLA3H8jGWSa1a097UKewBWrNWLWN"></script>
<script src="http://www.mapquestapi.com/sdk/leaflet/v2.s/mq-geocoding.js?key=sv99PLA3H8jGWSa1a097UKewBWrNWLWN"></script>
<div id="map"></div>
CSS
html, body, #map {
height: 100%;
width:100%;
padding:0px;
margin:0px;
background: white;
}
JavaScript
map = L.map('map', {
layers: MQ.mapLayer(),
center: [34.05,-118.25],
zoom: 14 });
map.on('click', function(e) {
lat = e.latlng.lat;
lng = e.latlng.lng;
geocode = MQ.geocode().reverse(e.latlng).on('success', function(e) {
marker = L.marker([lat, lng]).addTo(map).bindPopup(geocode.describeLocation(e.result.best)).openPopup();
});
});