- Jan 2, 2006
- 10,455
- 35
- 91
I'm looking for a kick in the right direction. Not too sure how to design this. I'm doing this in Ruby on Rails and we've already created a RESTful API to grab pin data.
I have a big table of pin locations in PostGreSQL.
pin_id, longitude, latitude
I have a front page with GoogleMaps. I want to populate the map with all the pins on load.
Possibility 1:
Go into PostGreSQL and create an array called var locations with all the pin data.
Loop through this locations array and populate the map with pins.
Issues:
I would be essentially creating this array each time on load. It seems really inefficient to re-create an array each time. Lots of performance and memory issues.
Possibility 2:
Create the array, but just have it stored somewhere. The array will update itself only when a user adds a new pin location. On each page load the system just loops through this array and populates the map.
Possibility 3:
Have my Javascript loop through my database table directly. I'm really fuzzy on how to get this done though. It sounds like the most direct and efficient way to grab the data, unless there are some PostGreSQL performance issues that I'm not aware of?
pseudo-code:
I have a big table of pin locations in PostGreSQL.
pin_id, longitude, latitude
I have a front page with GoogleMaps. I want to populate the map with all the pins on load.
Possibility 1:
Go into PostGreSQL and create an array called var locations with all the pin data.
Loop through this locations array and populate the map with pins.
Issues:
I would be essentially creating this array each time on load. It seems really inefficient to re-create an array each time. Lots of performance and memory issues.
Possibility 2:
Create the array, but just have it stored somewhere. The array will update itself only when a user adds a new pin location. On each page load the system just loops through this array and populates the map.
Possibility 3:
Have my Javascript loop through my database table directly. I'm really fuzzy on how to get this done though. It sounds like the most direct and efficient way to grab the data, unless there are some PostGreSQL performance issues that I'm not aware of?
pseudo-code:
Code:
for (var pin_id = 0; pin_id < pinTable.size; pin_id++)
//This loops through every pin_id, and in essence, every pin
var pinID = pin_id
var long = pin.findby(pin_id).long
var lat = pin.findby(pin_id).lat
[code for adding pin on GoogleMaps]