Last active
December 14, 2015 18:09
-
-
Save xsurge83/5127370 to your computer and use it in GitHub Desktop.
Google Maps View
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
(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