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
Franchises and Categories
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'), useDeviceLocation: true, collection: [ 'category', 'franchise' ], }); L.mapquest.key = '8nIoYUx9GyjZsdehJySzjprSvZIqgM42'; var map = L.mapquest.map('map', { center: [39.50, -98.35], layers: L.mapquest.tileLayer('map'), zoom: 5 }); L.mapquest.control().addTo(map); let searchLayer = null; ps.on('change', (e) => { if (e.result.type === 'franchise' || e.result.type === 'category') { let search = L.mapquest.search(); search.place({ category: `sic:${e.result.sic[0]}`, 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 Franchises or Categories..." /> </body> </html>
Try It Now