A better experience traveling using Local Context Library

Place Chooser View

Place Chooser View

Place Details View

Place Details view

Photo

Photo view

Getting Started

<script src=”https://maps.googleapis.com/maps/api/js?libraries=localContext&v=beta&key=YOUR_API_KEY&callback=initMap” defer></script>
function initMap() { const localContextMapView = new google.maps.localContext.LocalContextMapView({
element: document.querySelector(‘#map’),
placeTypePreferences: [‘restaurant’],
maxPlaceCount: 12
});
localContextMapView.map.setOptions({
center: {lat: 47.6532809, lng: -122.3512206},
zoom: 8
});
}

LocalContextMapView

Technical Details

Demo Time

My town
Map located in GooglePlex showing Place Chooser view restaurants
Map located in GooglePlex showing Place Details view In-N-Out and route to get there
const placeTypePreferences = [
'restaurant'
];
const placeTypePreferences = [
'restaurant',
'electronics_store',
'supermarket'
];
Map located in GooglePlex showing Place Chooser view restaurants, supermarkets and electronic stores
function createLocalContextMapView(localContextMapViewOptions = {}, mapOptions = {}) {
const defaultLocalContextMapViewOptions = {
element: getMapElement(),
placeTypePreferences,
maxPlaceCount: 0
};

const mergedLocalContextMapViewOptions = {
…defaultLocalContextMapViewOptions,
…localContextMapViewOptions
};
const localContextMapView = new google.maps.localContext.LocalContextMapView(mergedLocalContextMapViewOptions); const defaultMapOptions = {
center: { lat: 18.1553086, lng: -95.1845618 },
zoom: 16,
styles: mapStyles
};
const mergeMapOptions = {
…defaultMapOptions,
…mapOptions
};
localContextMapView.map.setOptions(mergeMapOptions);
localContextMapView.maxPlaceCount = 12;
localContextMapView.directionsOptions = {
origin: mergeMapOptions.center
};
localContextMapView.search();
return localContextMapView;
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store