MapQuest.com
Business
Navigation
Getting Started
Developer Blog
Web SDKs
MapQuest.js
PlaceSearch.js
Examples
Basic
Fill out form
Find the Nearest Business
Franchises and Categories
Map the Results
No Style
Templating
APIs
Data Manager API
Directions API
Geocoding API
Icons API
Search API
Place Search API
Search Ahead API
Static Map API
Traffic API
Legacy Products
Leaflet Plugins
Tools
Lat/Lng Finder
Link to MapQuest
Share
Getting Started
Developer Blog
Documentation
Web SDKs
MapQuest.js
PlaceSearch.js
new
Examples
Basic
Fill out form
Find the Nearest Business
Franchises and Categories
Map the Results
No Style
Templating
APIs
Data Manager API
Directions API
Geocoding API
Icons API
Search API
Place Search API
Search Ahead API
Static Map API
Traffic API
Legacy Products
Leaflet Plugins
Tools
Lat/Lng Finder
Link to MapQuest
Share
PlaceSearch.js
Find the Nearest Business
Edit the code below and click "Try It Now" to display the result.
<html> <head> <script src="https://api.mqcdn.com/sdk/place-search-js/v1.0.0/place-search.js"></script> <link type="text/css" rel="stylesheet" href="https://api.mqcdn.com/sdk/place-search-js/v1.0.0/place-search.css"/> <script src="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.js"></script> <link type="text/css" rel="stylesheet" href="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.css"/> <script type="text/javascript"> window.onload = function() { let ps = placeSearch({ key: '8nIoYUx9GyjZsdehJySzjprSvZIqgM42', container: document.querySelector('#search-input'), collection: [ 'adminArea', 'address', ], useDeviceLocation: true }); L.mapquest.key = '8nIoYUx9GyjZsdehJySzjprSvZIqgM42'; let baseLayer = L.mapquest.tileLayer('map'); let map = L.mapquest.map('map', { center: [39.50, -98.35], layers: baseLayer, zoom: 5 }); L.mapquest.control().addTo(map); let searchLayer = null; ps.on('change', (e) => { let zoom = 13; if (e.result.type === 'state') { zoom = 8 } map.setView(e.result.latlng, zoom); let search = L.mapquest.search(); search.place({ category: 'sic:581228F52', sort: 'relevance', bbox: map.getBounds(), pageSize: 20 }, handleSearch); }); function handleSearch(err, data) { if (searchLayer) { map.removeLayer(searchLayer); } searchLayer = L.mapquest.searchLayer({ searchResponse: data }); map.addLayer(searchLayer); } ps.on('clear', () => { if (searchLayer) { map.removeLayer(searchLayer); } searchLayer = null; map.setView(new L.LatLng(39.50, -98.35), 5); }); ps.on('error', (e) => { console.log(e); }); } </script> </head> <body style="border: 0; margin: 40px;"> <div id="map" style="width: 100%; height: 530px;"></div> <input type="search" id="search-input" placeholder="Find the nearest Starbucks..." /> </body> </html>
Try It Now