Skip to content

Instantly share code, notes, and snippets.

@xsurge83
Last active December 14, 2015 18:09
Show Gist options
  • Save xsurge83/5127370 to your computer and use it in GitHub Desktop.
Save xsurge83/5127370 to your computer and use it in GitHub Desktop.
Google Maps View
(function(exports, $) {
var MapView;
MapView = (function() {
function MapView(mapId, defaultLocation, map) {
self = this;
var location = BrowserUtils.getParamFromQuery('query');
if (!location) {
location = defaultLocation;
}
this.addressElem = document.getElementById('address');
this.addressElem.value = location;
if (!map) {
var mapElem = document.getElementById("map_canvas");
this.map = new GMap(mapElem);
}
else{
this.map = map;
}
}
var getClubs = function(searchResult, callback) {
$.post("/Search/SearchByLocation", searchResult,
callback,
"json");
}
var addClubsToMap = function(clubs) {
console.log("my clubs %J", clubs);
self.map.addMarkers(clubs);
};
MapView.prototype.searchLocation = function(location) {
if (typeof location !== "string" || !location) {
location = document.getElementById("address").value
}
this.map.geocode(location, function(error, searchResult) {
try {
if (error == "OK") {
searchResult.search = location
getClubs(searchResult, addClubsToMap);
}
} catch (error) {
console.log("unable to get map coordinates %j", error);
}
});
};
return MapView;
})();
$(document).ready(function() {
var mapId = "map_canvas";
var mapView = new MapView(mapId, "New York, NY");
mapView.searchLocation(location)
exports.mapView = mapView
})
}(typeof exports === 'undefined' ? this['mymodule'] = {} : exports, jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment