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
4 _g
['host_back'] = 'cubito.ath.cx:3000'
5 _g
.retries
= {}; // Used to keep count of retries by address
7 function searchAndPin() {
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
) {
20 for(var i
=0;i
<venues
.length
;i
++) {
21 var venue
= venues
[i
];
22 put_pin(venue
.lat
, venue
["long"], venue
.name
);
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",
42 _g.map.setCenter( pt, 15);
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
51 // Creates listener to check for map repositioning
52 GEvent
.addListener(_g
.map
,"moveend",function (){
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
);
68 function get_resto_list( parameters
, callback
) {
69 new Ajax
.ScriptRequest( "http://" + _g
['host_back'] + "/venues/viewport", {
70 parameters
: parameters
,
72 callbackName
: "callback",
73 onFailure: function( e
) {
74 alert("Error listing restaurants: " + e
);