Skip to content

Instantly share code, notes, and snippets.

@alco
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alco/bb46f4fb52b092f28974 to your computer and use it in GitHub Desktop.
Save alco/bb46f4fb52b092f28974 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@import url("http://github.com/simplegeo/polymaps/raw/v2.4.0/examples/example.css");
html, body {height: 100%;}
svg {display: block;}
.layer circle {fill: #f00;stroke: #000;stroke-width: 2px;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="https://gist.githubusercontent.com/alco/bb46f4fb52b092f28974/raw/b12308daa1779f957dccd95b3d561f044207602f/simplegeo.all.jq.min.js"></script>
<script type="text/javascript" src="http://github.com/simplegeo/polymaps/raw/v2.4.0/polymaps.js"></script>
</head>
<body>
<script type="text/javascript">
var client = new simplegeo.PlacesClient('E3mbEYGWRppsZtxAXbd3cm6PGaLUHTSz');
var address = "41 Decatur St, San Francisco, CA";
var po = org.polymaps;
var map = po.map()
.container(document.body.appendChild(po.svg("svg")))
.center({lat: 37.772326, lon: -122.405784})
.zoom(17)
.zoomRange([12, 18])
.add(po.interact());
map.add(po.image()
.url(po.url("http://{S}tile.cloudmade.com"
+ "/5814d279db61404b9e52115b06b9e7b3" // http://cloudmade.com/register
+ "/1714/256/{Z}/{X}/{Y}.png")
.hosts(["a.", "b.", "c.", ""])));
var geoJson = po.geoJson();
map.add(geoJson);
map.add(po.compass()
.pan("none"));
client.searchFromAddress(address, function(err, data) {
if (err) {
console.error(err);
} else {
geoJson.features(data.features);
}
});
</script>
</body>
</html>
(function(j,g){(function(k){var d=j.simplegeo;if(d===g)d={};if(d.Client===g){d.Client=function(b,a){if(!(this instanceof d.Client))return new d.Client(b,a);a=a||{};this.token=b;this.options=a;this.host=a.host||"api.simplegeo.com";this.port=a.port||"80";this.apiUrl="http://"+this.host+":"+this.port;this.name="Client"};var i=j.navigator;d.Client.prototype={request:function(b,a,c){a.token=this.token;a=k.param(a)+"&callback=?";k.ajax({url:this.apiUrl+b,dataType:"json",data:a,success:function(e){if(e.error){var f=
Error(e.message);f.code=e.code;c(f)}else c(null,e.data)},error:function(e,f,l){c(l)}})},getFeature:function(b,a,c){if(c===g){c=a;a={}}return this.request("/1.0/features/"+b+".json",a,c)},watchLocationFromBrowser:function(b,a){if(a===g){a=b;b={}}i&&i.geolocation?i.geolocation.watchPosition(function(c){c.source="navigator";a(null,c)},function(c){a(c)},b):a(Error("navigator.geolocation not available"))},getLocationFromBrowser:function(b,a){if(a===g){a=b;b={}}i&&i.geolocation?i.geolocation.getCurrentPosition(function(c){c.source=
"navigator";a(null,c)},function(c){a(c)},b):a(Error("navigator.geolocation not available"))},getLocationFromIP:function(b,a){var c;if(a===g){a=b;c="/0.1/locate.json"}else c="/0.1/locate/"+b+".json";return this.request(c,{},function(e,f){e?a(e):a(null,{coords:{latitude:f.geometry.coordinates[1],longitude:f.geometry.coordinates[0],accuracy:1E5},timestamp:new Date,source:"simplegeo"})})},getLocation:function(b,a){var c=this;if(a===g){a=b;b={}}c.getLocationFromBrowser(b,function(e,f){e?c.getLocationFromIP(a):
a(null,f)})}}}d.StorageClient=function(b,a){if(!(this instanceof d.StorageClient))return new d.StorageClient(b,a);d.Client.call(this,b,a);this.name="StorageClient"};d.StorageClient.prototype=new d.Client;var h={record:"/0.1/records/layer/id.json",records:"/0.1/records/layer/ids.json",history:"/0.1/records/layer/id/history.json",nearby:"/0.1/records/layer/nearby/arg.json",nearbyAddress:"/0.1/nearby/address/lat,lon.json",densityDay:"/0.1/density/day/lat,lon.json",densityHour:"/0.1/density/day/hour/lat,lon.json"};
d.StorageClient.prototype.getRecord=function(b,a,c){path=h.record;path=path.replace("layer",b).replace("id",a);return this.request(path,{},c)};d.StorageClient.prototype.getRecords=function(b,a,c){path=h.records;idString=a.join(",");path=path.replace("layer",b).replace("ids",idString);return this.request(path,{},c)};d.StorageClient.prototype.getHistory=function(b,a,c,e){if(e===g){e=c;c={}}path=h.history;path=path.replace("layer",b).replace("id",a);return this.request(path,c,e)};d.StorageClient.prototype.getNearby=
function(b,a,c,e,f){if(f===g){f=e;e={}}path=h.nearby;path=path.replace("layer",b).replace("arg",a+","+c);return this.request(path,e,f)};d.StorageClient.prototype.getNearbyGeohash=function(b,a,c,e){if(e===g){e=c;c={}}path=h.nearby;path=path.replace("layer",b).replace("arg",a);return this.request(path,c,e)};d.StorageClient.prototype.getNearbyAddress=function(b,a,c){path=h.nearbyAddress;path=path.replace("lat",b).replace("lon",a);return this.request(path,{},c)};d.StorageClient.prototype.getDensity=function(b,
a,c,e,f){if(f===g){f=e;path=h.densityDay;path=path.replace("day",c).replace("lat",b).replace("lon",a)}else{path=h.densityHour;path=path.replace("day",c).replace("hour",e).replace("lat",b).replace("lon",a)}return this.request(path,{},f)};d.ContextClient=function(b,a){if(!(this instanceof d.ContextClient))return new d.ContextClient(b,a);d.Client.call(this,b,a);this.name="ContextClient"};d.ContextClient.prototype=new d.Client;d.ContextClient.prototype.getContext=function(b,a,c){return this.request("/1.0/context/"+
b+","+a+".json",{},c)};d.ContextClient.prototype.getContextFromIP=function(b,a){if(a===g){a=b;b="ip"}return this.request("/1.0/context/"+b+".json",{},a)};d.ContextClient.prototype.getContextFromAddress=function(b,a){return this.request("/1.0/context/address.json",{address:b},a)};d.PlacesClient=function(b,a){if(!(this instanceof d.PlacesClient))return new d.PlacesClient(b,a);d.Client.call(this,b,a);this.name="PlacesClient"};d.PlacesClient.prototype=new d.Client;d.PlacesClient.prototype.search=function(b,
a,c,e){if(e===g){e=c;c={}}var f="/1.0/places/lat,lon.json";f=f.replace("lat",b).replace("lon",a);return this.request(f,c,e)};d.PlacesClient.prototype.searchFromIP=function(b,a,c){if(arguments.length===2){c=a;if(b.trim)a={};else{a=b;b="ip"}}else if(arguments.length===1){c=b;b="ip";a={}}return this.request("/1.0/places/"+b+".json",a,c)};d.PlacesClient.prototype.searchFromAddress=function(b,a,c){if(c===g){c=a;a={}}a.address=b;return this.request("/1.0/places/address.json",a,c)};j.simplegeo=d})(jQuery)})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment