added necessary function ;)
[donde.git] / donde / donde.js
blobd6e1a5b443757c022db638209281c2a5f7dba584
1 // We use this global variable to store re-usable objects
2 // If this grows too big, it's time to re-think the approach
3 var _g = {};
4 _g['host_back'] = 'cubito.ath.cx:3000'
5 _g.retries = {}; // Used to keep count of retries by address
7 function searchAndPin() {
8 // Get map bounds
9 var bounds = _g.map.getBounds();
10 var sw = bounds.getSouthWest();
11 var ne = bounds.getNorthEast();
12 document.getElementById("latlng").innerHTML=_g.map.getCenter();
14 // Clear current Overlays
15 _g.map.clearOverlays();
17 // Query restaurants in that area and puts a pin for each found
18 get_resto_list({a0:sw.lat(),o0:sw.lng(),a1:ne.lat(),o1:ne.lng()},function(data) {
19 var venues = data;
20 for(var i=0;i<venues.length;i++) {
21 var venue = venues[i];
22 put_pin(venue.lat, venue["long"], venue.name);
24 });
26 function main(){
27 if (!GBrowserIsCompatible()) {
28 alert("Browser not compatible");
31 // Create map and store as global
32 _g.map = new GMap2(document.getElementById("map"));
33 _g.map.addControl(new GLargeMapControl());
35 // Create goecoder and store as global
36 _g.geocoder = new GClientGeocoder();
37 _g.geocoder.setBaseCountryCode("ar");
39 // Position map arbitrarily in Nuñez
40 /* _g.geocoder.getLatLng("nuñez, capital federal, argentina",
41 function( pt) {
42 _g.map.setCenter( pt, 15);
43 });
45 // Position map arbitrarily in Nuñez without geocoding
46 _g.map.setCenter(new GLatLng(-34.5585098, -58.4824486),15);
48 // Searches current map position and puts pins
49 searchAndPin();
51 // Creates listener to check for map repositioning
52 GEvent.addListener(_g.map,"moveend",function (){
53 searchAndPin();
54 });
57 /**
58 * Puts a pin in the map, given lat, lng and a name (from venues)
60 function put_pin( lat, lng, name) {
61 var marker = new GMarker(new GLatLng(lat, lng));
62 _g.map.addOverlay( marker, {clickable: true});
63 GEvent.addListener( marker, "click", function() {
64 marker.openInfoWindow(name);
65 });
68 function get_resto_list( parameters, callback) {
69 new Ajax.ScriptRequest( "http://" + _g['host_back'] + "/venues/viewport", {
70 parameters: parameters,
71 onResponse: callback,
72 callbackName: "callback",
73 onFailure: function( e) {
74 alert("Error listing restaurants: " + e);
76 });