Skip to content

Instantly share code, notes, and snippets.

@stevelacey
Last active May 10, 2024 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevelacey/fc1d3b2ac5b2fe19c927 to your computer and use it in GitHub Desktop.
Save stevelacey/fc1d3b2ac5b2fe19c927 to your computer and use it in GitHub Desktop.
var geocoder = new google.maps.Geocoder();
var trips = [
{ action: 'trip', date_start: '2000-10-21', date_end: '2000-10-29', city: 'Fuerteventura', country: 'Spain' },
{ action: 'trip', date_start: '2000-10-29', date_end: '2000-12-28', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2000-12-28', date_end: '2001-01-04', city: 'Lagos', country: 'Portugal' },
{ action: 'trip', date_start: '2001-01-04', date_end: '2001-04-08', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2001-04-08', date_end: '2001-04-15', city: 'Paphos', country: 'Cyprus' },
{ action: 'trip', date_start: '2001-04-15', date_end: '2001-08-27', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2001-08-27', date_end: '2001-08-31', city: 'Nice', country: 'France' },
{ action: 'trip', date_start: '2001-08-31', date_end: '2001-10-27', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2001-10-27', date_end: '2001-11-04', city: 'Paphos', country: 'Cyprus' },
{ action: 'trip', date_start: '2001-11-04', date_end: '2001-12-29', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2001-12-29', date_end: '2002-01-05', city: 'Majorca', country: 'Spain' },
{ action: 'trip', date_start: '2002-01-05', date_end: '2002-03-29', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2002-03-29', date_end: '2002-04-03', city: 'Latchi', country: 'Cyprus' },
{ action: 'trip', date_start: '2002-04-03', date_end: '2002-06-02', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2002-06-02', date_end: '2002-06-06', city: 'Nice', country: 'France' },
{ action: 'trip', date_start: '2002-06-06', date_end: '2002-10-27', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2002-10-27', date_end: '2002-11-03', city: 'Latchi', country: 'Cyprus' },
{ action: 'trip', date_start: '2002-11-03', date_end: '2002-12-28', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2002-12-28', date_end: '2003-01-04', city: 'Lagos', country: 'Portugal' },
{ action: 'trip', date_start: '2003-01-04', date_end: '2003-04-16', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2003-04-16', date_end: '2003-04-23', city: 'Rhodes', country: 'Greece' },
{ action: 'trip', date_start: '2003-04-23', date_end: '2003-05-25', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2003-05-25', date_end: '2003-06-01', city: 'Stoupa', country: 'Greece' },
{ action: 'trip', date_start: '2003-06-01', date_end: '2003-08-29', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2003-08-29', date_end: '2003-09-02', city: 'Nice', country: 'France' },
{ action: 'trip', date_start: '2003-09-02', date_end: '2003-10-26', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2003-10-26', date_end: '2003-12-13', city: 'Latchi', country: 'Cyprus' },
{ action: 'trip', date_start: '2003-12-13', date_end: '2003-12-28', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2003-12-28', date_end: '2004-01-04', city: 'Paphos', country: 'Cyprus' },
{ action: 'trip', date_start: '2004-01-04', date_end: '2004-07-18', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2004-07-18', date_end: '2004-07-25', city: 'Boston', country: 'USA' },
{ action: 'trip', date_start: '2004-07-25', date_end: '2004-07-27', city: 'Toronto', country: 'Canada' },
{ action: 'trip', date_start: '2004-07-27', date_end: '2004-07-30', city: 'Niagara', country: 'Canada' },
{ action: 'trip', date_start: '2004-07-30', date_end: '2004-08-05', city: 'Boston', country: 'USA' },
{ action: 'trip', date_start: '2004-08-05', date_end: '2004-12-27', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2004-12-27', date_end: '2005-01-03', city: 'Madeira', country: 'Portugal' },
{ action: 'trip', date_start: '2005-01-03', date_end: '2005-07-20', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2005-07-20', date_end: '2005-07-24', city: 'Boston', country: 'USA' },
{ action: 'trip', date_start: '2005-07-24', date_end: '2005-07-26', city: 'Montreal', country: 'Canada' },
{ action: 'trip', date_start: '2005-07-26', date_end: '2005-07-28', city: 'Quebec', country: 'Canada' },
{ action: 'trip', date_start: '2005-07-28', date_end: '2005-07-29', city: 'Montreal', country: 'Canada' },
{ action: 'trip', date_start: '2005-07-29', date_end: '2005-08-07', city: 'Cape Cod', country: 'USA' },
{ action: 'trip', date_start: '2005-08-07', date_end: '2005-08-11', city: 'Boston', country: 'USA' },
{ action: 'trip', date_start: '2005-08-11', date_end: '2005-12-22', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2005-12-22', date_end: '2005-12-29', city: 'Lagos', country: 'Portugal' },
{ action: 'trip', date_start: '2005-12-29', date_end: '2006-04-13', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2006-04-13', date_end: '2006-04-18', city: 'Gibraltar', country: 'Gibraltar' },
];
function geocode_and_submit(trip) {
geocoder.geocode({'address': trip.city + ', ' + trip.country}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
loc = results[0].geometry.location;
trip.latitude = loc.lat();
trip.longitude = loc.lng();
$.ajax({
url: '/user/api/',
dataType: 'json',
type: 'PUT',
data: trip
});
}
});
}
for (var i=0; i<trips.length; i++) {
var trip = trips[i];
geocode_and_submit(trip)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment