Created
May 24, 2016 10:13
-
-
Save daveroma/4671dce53a9c093287db5e72e35812d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var M = M || {}; | |
M.lenderMap = function(defaultCenter) { | |
var map; | |
var infoWindow; | |
var service; | |
var infoWindowTemplate = function(result) { | |
return '<div class="info-window">' + | |
'<h3>' + result.name + '</h3>' + | |
'<span>' + result.formatted_address.replace(', United States', '') + '</span>' + | |
'<span>' + result.formatted_phone_number + '</span>' + | |
'<a href="' + result.website + '" target="_blank">Visit website</a>' + | |
'</div>' | |
} | |
function performSearch() { | |
var request = { | |
bounds: map.getBounds(), | |
keyword: 'mortgage' | |
}; | |
service.radarSearch(request, callback); | |
} | |
function callback(results, status) { | |
if (status !== google.maps.places.PlacesServiceStatus.OK) { | |
return; | |
} | |
for (var i = 0, result; result = results[i]; i++) { | |
addMarker(result); | |
} | |
} | |
function addMarker(place) { | |
var marker = new google.maps.Marker({ | |
map: map, | |
position: place.geometry.location, | |
icon: { | |
url: '/img/icons/map-marker-icon-60x60.png', | |
anchor: new google.maps.Point(10, 10), | |
scaledSize: new google.maps.Size(30, 30) | |
} | |
}); | |
google.maps.event.addListener(marker, 'click', function() { | |
service.getDetails(place, function(result, status) { | |
if (status !== google.maps.places.PlacesServiceStatus.OK) { | |
return; | |
} | |
infoWindow.setContent(infoWindowTemplate(result)); | |
infoWindow.open(map, marker); | |
}); | |
}); | |
} | |
return { | |
init: function() { | |
map = new google.maps.Map(document.getElementById('map'), { | |
center: defaultCenter, | |
zoom: 14, | |
scrollwheel: false, | |
styles: M.map.styles | |
}); | |
infoWindow = new google.maps.InfoWindow(); | |
service = new google.maps.places.PlacesService(map); | |
// The idle event is a debounced event, so we can query & listen without | |
// throwing too many requests at the server. | |
map.addListener('idle', performSearch); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment