Created
October 24, 2011 12:30
-
-
Save mildfuzz/1308913 to your computer and use it in GitHub Desktop.
geoLocal JS
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 scripts = {}; | |
| var w3cGeo = {}; | |
| w3cGeo.api = '95b5c8ffb1d0891fe5a1eed66ce0d2d5'; | |
| var gLocalSearch = new GlocalSearch(); | |
| google.load("search", "1"); | |
| google.load("maps", "2", {"callback" : w3cGeo.mapsLoaded}); | |
| scripts.loadJS = function(url){ | |
| var script = document.createElement("script"); | |
| script.type = "text/javascript"; | |
| script.src = url; | |
| document.getElementsByTagName("head")[0].appendChild(script); | |
| } | |
| /* | |
| Loads <script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script> | |
| Use as Fallback to other methods | |
| */ | |
| scripts.loadJS("http://j.maxmind.com/app/geoip.js"); | |
| /* | |
| Google API | |
| */ | |
| w3cGeo.searchLoaded = function(){ | |
| function myMaxMind () { | |
| this.lat = geoip_latitude(); | |
| this.lon = geoip_longitude(); | |
| this.city = geoip_city(); | |
| }; | |
| var mmLoc = new myMaxMind(); | |
| if(navigator.geolocation){ | |
| // get the current position | |
| navigator.geolocation.getCurrentPosition( | |
| // if this was successful, get the latitude and longitude | |
| function(position){ | |
| w3cGeo.lat = position.coords.latitude; | |
| w3cGeo.lon = position.coords.longitude; | |
| //getPlaceFromFlickr(w3cGeo.lat,w3cGeo.lon,'output'); | |
| getPlaceFromGoogle(w3cGeo.lat,w3cGeo.lon); | |
| }, | |
| // if there was an error | |
| function(error){ | |
| w3cGeo.center = new google.maps.LatLng(mmLoc.lat,mmLoc.lon) | |
| get_LocalSearch(); | |
| }); | |
| } | |
| } | |
| w3cGeo.mapsLoaded = function(){ | |
| // if the browser supports the w3c geo api | |
| } | |
| function get_LocalSearch(){ | |
| var query = 'curry'; | |
| gLocalSearch.setCenterPoint(w3cGeo.center); | |
| gLocalSearch.setResultSetSize(5); | |
| gLocalSearch.setNoHtmlGeneration(); | |
| gLocalSearch.setSearchCompleteCallback(null, OnLocalSearch); | |
| gLocalSearch.execute(query); | |
| } | |
| // Called when Local Search results are returned, we clear the old | |
| // results and load the new ones. | |
| function OnLocalSearch() { | |
| if (!gLocalSearch.results) return; | |
| console.log(gLocalSearch.results,'results'); | |
| } | |
| //------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment