diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-06 13:05:24 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-06 13:05:24 +0100 |
commit | 5ea25c06ade6453297ff30f7656cabdb967cc9c1 (patch) | |
tree | 41954e838a61c6eec9ec2d7f562366a58b5bec87 | |
parent | 2954948be187c096ad86aeb6af6ad3a0d188508c (diff) |
use location finding from lcoation controller
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 83 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 2 |
2 files changed, 3 insertions, 82 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index cb1ce8573..92cd1556a 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -41,8 +41,8 @@ sub around_index : Path : Args(0) { # Try to create a location for whatever we have return - unless $c->forward('determine_location_from_coords') - || $c->forward('determine_location_from_pc'); + unless $c->forward('/location/determine_location_from_coords') + || $c->forward('/location/determine_location_from_pc'); # Check to see if the spot is covered by a council - if not show an error. return unless $c->forward('check_location_is_acceptable'); @@ -234,85 +234,6 @@ sub display_location : Private { return 1; } -=head2 determine_location_from_coords - -Use latitude and longitude if provided in parameters. - -=cut - -sub determine_location_from_coords : Private { - my ( $self, $c ) = @_; - - my $latitude = $c->req->param('latitude') || $c->req->param('lat'); - my $longitude = $c->req->param('longitude') || $c->req->param('lon'); - - if ( defined $latitude && defined $longitude ) { - $c->stash->{latitude} = $latitude; - $c->stash->{longitude} = $longitude; - - # Also save the pc if there is one - if ( my $pc = $c->req->param('pc') ) { - $c->stash->{pc} = $pc; - } - - return 1; - } - - return; -} - -=head2 determine_location_from_pc - -User has searched for a location - try to find it for them. - -If one match is found returns true and lat/lng is set. - -If several possible matches are found puts an array onto stash so that user can be prompted to pick one and returns false. - -If no matches are found returns false. - -=cut - -sub determine_location_from_pc : Private { - my ( $self, $c ) = @_; - - # check for something to search - my $pc = $c->req->param('pc') || return; - $c->stash->{pc} = $pc; # for template - - my ( $latitude, $longitude, $error ) = - eval { FixMyStreet::Geocode::lookup( $pc, $c->fake_q ) }; - - # Check that nothing blew up - if ($@) { - warn "Error: $@"; - return; - } - - # If we got a lat/lng set to stash and return true - if ( defined $latitude && defined $longitude ) { - $c->stash->{latitude} = $latitude; - $c->stash->{longitude} = $longitude; - return 1; - } - - # $error doubles up to return multiple choices by being an array - if ( ref($error) eq 'ARRAY' ) { - @$error = map { - decode_utf8($_); - s/, United Kingdom//; - s/, UK//; - $_; - } @$error; - $c->stash->{possible_location_matches} = $error; - return; - } - - # pass errors back to the template - $c->stash->{location_error} = $error; - return; -} - =head2 check_location_is_acceptable Find the lat and lon in stash and check that they are acceptable to the council, diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index e19cdf403..e16739458 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -377,7 +377,7 @@ sub determine_location : Private { if # ( # $c->forward('determine_location_from_tile_click') - || $c->forward('/around/determine_location_from_coords') + || $c->forward('/location/determine_location_from_coords') || $c->forward('determine_location_from_report') ) # && $c->forward('/around/check_location_is_acceptable'); |