{"id":433,"date":"2013-08-23T19:56:24","date_gmt":"2013-08-24T00:56:24","guid":{"rendered":"http:\/\/www.aibistin.com\/?p=433"},"modified":"2013-08-25T21:09:44","modified_gmt":"2013-08-26T02:09:44","slug":"new-york-city-household-furniture-moving-travel-time-calculator","status":"publish","type":"post","link":"https:\/\/www.aibistin.com\/?p=433","title":{"rendered":"New York City Household Furniture Moving Travel Time Calculator"},"content":{"rendered":"<p class=\"important\">\nMy next project is to create a travel time calculator application using Dancer2. Hopefully, this would be useful to any household furniture moving company operating in New York City.<br \/>\nWhen charging for the travel time between two locations, many New York City Moving companies use the following DOT guidelines.\n<\/p>\n<ol>\n<li>1\/2 an hour within any borough.<\/li>\n<li>3\/4 an hour from one borough to another.<\/li>\n<li>1 hour for the first 20 miles between locations that either start or end within New York City<\/li>\n<li>1 hour for each 40 miles after the first 20 miles, which is equivalent to 15 minutes for each 10 miles.<\/li>\n<\/ol>\n<p>\n Most of the information that I need to get the distances between locations is freely available from Google&#8217;s <a href=\"https:\/\/developers.google.com\/maps\/documentation\/distancematrix\/\" title=\"Google Distance Matrix API\" target=\"_blank\">Distance Matrix API<\/a>. I checked out CPAN to see if there was a suitable module available to access this API. There were some that partially did what I required, but not all of what I required.<br \/>\nI decided to write my own, which you can read about <a class=\"vital-link\"  href=\"http:\/\/www.aibistin.com\/?p=290\" title=\"Google Distance Matrix API Module Story\">here<\/a>.\n<\/p>\n<p class=\"code-heading\">Forms:<\/p>\n<p><span class=\"code-description\">Form To Input Addresses<\/span><\/p>\n<p>\nThere are two methods of User Input that I wanted to experiment with. The first is by means of a form where you would enter the exact origin and destination addresses. I describe this in detail <a class=\"vital-link\" href=\"http:\/\/www.aibistin.com\/?p=427\" title=\"FormHandler Address Form Post\" target=\"_blank\">here<\/a>.<br \/>\nThe second method, using jQuery autocomplete, I discuss <a class=\"vital-link\"  href=\"http:\/\/www.aibistin.com\/?p=389\" title=\"Bootstrap Typeahead Post\" target=\"_blank\">here<\/a>.<\/p>\n<p class=\"code-heading\">Dancer2 Application TravelTime<\/p>\n<p><span class=\"code-description\">The Perl App that implements the <a class=\"vital-link\"  href=\"https:\/\/github.com\/aibistin\/TravelTime\" title=\"TravelTime\"  target=\"_blank\">Travel Time Calculator<\/a><\/span><\/p>\n<p> I used the Perl <a href=\"https:\/\/metacpan.org\/module\/Dancer2\" target=\"_blank\">Dancer2<\/a> framework for building this application. Dancer2 bills itself as a &#8220;Lightweight yet powerful web application framework&#8221;, which I guess is true. It works well for me and is not too complex. I did run into a few bugs which seem to  have been ironed out in the very latest version. So, it does have an active group of developers who are maintaining and upgrading this software. Thank you for that.<br \/>\nHere is an excerpt from this module, showing one particular route handler. This particular one handles an Ajax call to provide a list of cities that match a specific search criteria. The Dancer2::Plugin::Ajax helps out with this method. The caller in this case is a JavaScript program that I use to implement a jQuery autocomplete input field. You can read about this <a class=\"vital-link\"  href=\"http:\/\/www.aibistin.com\/?p=389 \" title=\"City State County Ajax call using Bootstrap Typeahead\" target=\"_blank\">here<\/a>\n<\/p>\n<pre class=\"brush: css; auto-links: false; collapse: false; first-line: 1; gutter: true; light: false; pad-line-numbers: false; smart-tabs: false; tab-size: 4; title: Sample code from TravelTime.pm; toolbar: true; notranslate\" title=\"Sample code from TravelTime.pm\">\r\n#-------------------------------------------------------------------------------\r\n#    Get a list of city, states and counties.\r\n#-------------------------------------------------------------------------------\r\najax '\/city_states' =&gt; sub {\r\n    \r\n    #------ Trim  whitespace from lhs and append the '%' SQL match char.\r\n    #       This will handle searches like 'Sunn,      New York' (Sunnyside, New York)\r\n    #       or                             'Kew Gar,      New York' (Kew Gardens,  New York)\r\n    #       or                             'Kew,New York'\r\n    my @find_params =\r\n      map { $_ =~ s\/^\\s+\/\/; s\/\\s+\\z\/\/; $_ . '%' }\r\n      split( ',', params-&gt;{find} );\r\n    debug 'The find params array now contains : ' . dump @find_params;\r\n\r\n    my $csc_arr;\r\n\r\n    #------ Allow some short cuts for the Big Apple\r\n    if ( $find_params&#x5B;0] =~ \/^(nyc|manhattan|base)%\\z\/i ) {\r\n        $csc_arr-&gt;&#x5B;0] = &#x5B; 'New York City', 'New York', 'New York County' ];\r\n    }\r\n    else {\r\n\r\n        #----- Search DB for City and Counties matching the search params.\r\n        connect_to_cities() unless $DBH;\r\n        process_error( { Error =&gt; 'Unable to connect to the City, State,\r\n                county database! Please try later!', } ) unless $DBH;\r\n        $csc_arr = select_city_state_cty( $DBH, \\@find_params );\r\n    }\r\n\r\n    #------ Returns sorted list of Cities, States and Counties to\r\n    #       city-states.js\r\n    { city_states =&gt; $csc_arr };\r\n};\r\n<\/pre>\n<p>Have a look at the entire Application code on <a class=\"vital-link\"   href=\"https:\/\/github.com\/aibistin\/TravelTime\" title=\"TravelTime Dancer2 web application\" target=\"_blank\">GitHub<\/a>.<br \/>\nFor a live demo, here is the <a class=\"vital-link\" href=\"http:\/\/www.carryonmoving.net\/quick\" title=\"CarryOnMoving.net\" target=\"_blank\">Moving Truck Travel Time Calculator<\/a> application running on the <a href=\"https:\/\/www.dotcloud.com\/\" title=\"dotCloud\" target=\"_blank\">dotCloud <\/a> hosting service.<br \/>\n<a class=\"vital-link\" href=\" http:\/\/www.aibistin.com\/?p=459\" title=\"Deploy To dotCloud\">This is how I deployed my Dancer2 Application to dotCloud<\/a>.<\/p>\n<p>\n<a href=\"https:\/\/twitter.com\/aibistin\" class=\"twitter-follow-button\" data-show-count=\"false\" >Follow @aibistin<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My next project is to create a travel time calculator application using Dancer2. Hopefully, this would be useful to any household furniture moving company operating in New York City. When charging for the travel time between two locations, many New York City Moving companies use the following DOT guidelines. 1\/2 an hour within any borough. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[9,7,21,23,12,20,22],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bootstrap","tag-dancer","tag-dancer2","tag-htmlformhandler","tag-moose","tag-perl","tag-templatetoolkit"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.aibistin.com\/index.php?rest_route=\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aibistin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aibistin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aibistin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aibistin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=433"}],"version-history":[{"count":15,"href":"https:\/\/www.aibistin.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":560,"href":"https:\/\/www.aibistin.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions\/560"}],"wp:attachment":[{"href":"https:\/\/www.aibistin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aibistin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aibistin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}