Show closest places to route within boundary
by limeric29
HTML
<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>
<body onload="initialize();">
<div id="map" style="width: 500px; height: 400px;"></div>
Keyword: <input type="text" id="keyword" value="coffee"/>
<input type="submit" onclick="route()"/>
<h2>Results</h2>
<ul id="places"></ul>
</body>
JavaScript
var map = null;
var boxpolys = null;
var directions = null;
var infowindow;
var service;
var markersArray = []; //marker array
function initialize() {
// Default the map view to the continental U.S.
var mapOptions = {
center: new google.maps.LatLng(37.09024, -95.712891),
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 4
};
var infoWindowOptions = {
maxWidth: 360
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
infowindow = new google.maps.InfoWindow(infoWindowOptions);
service = new google.maps.places.PlacesService(map);
directionService = new google.maps.DirectionsService();
directionsRenderer = new google.maps.DirectionsRenderer({
map: map
});
}
function route() {
// Clear any previous route boxes from the map
clearBoxes();
// Clear any previous markers from the map
deleteOverlays();
var request = {
origin: "miami flordia",
destination: "tamiami florida",
travelMode: google.maps.DirectionsTravelMode.DRIVING
}
// Make the directions request
directionService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer.setDirections(result);
//search within boundaries
bounds = new google.maps.LatLngBounds(new google.maps.LatLng(25.75936182169444, -80.35907120698232),
new google.maps.LatLng(25.802781356611113, -80.24656672402358));
//draw box around boundaries
drawBoxes(bounds);
} else {
alert("Directions query failed: " + status);
}
// Perform search over this bounds
var request = {
bounds: bounds,
...