diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 7bfdbf16f7a..201efe2bcca 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -133,6 +133,22 @@ sub upload : Local { $out = { id => $fileid }; } + if ($c->get_param('get_latlon') && $c->stash->{photo_gps}) { + $out = { + %$out, + %{ $c->stash->{photo_gps} }, + }; + } + + if ($c->get_param('start_report') && $c->stash->{photo_gps}) { + my $url = $c->uri_for( "/report/new", { + lat => $c->stash->{photo_gps}->{lat}, + lon => $c->stash->{photo_gps}->{lon}, + photo_id => $fileid, + } ); + return $c->res->redirect($url); + } + $c->res->content_type('application/json; charset=utf-8'); $c->res->body(encode_json($out)); } diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index d6504f2dec3..61aceb1325a 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -639,6 +639,10 @@ sub initialize_report : Private { $report = $c->model('DB::Problem')->new( {} ); } + if (!$c->stash->{upload_fileid} && $c->get_param('photo_id')) { + $c->stash->{upload_fileid} = $c->get_param('photo_id'); + } + # If we have a user logged in let's prefill some values for them. if (!$report->user && $c->user) { my $user = $c->user->obj; diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm index b8477617807..17675cdc8f9 100644 --- a/perllib/FixMyStreet/App/Model/PhotoSet.pm +++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm @@ -177,6 +177,11 @@ has ids => ( # Arrayref of $fileid tuples (always, so post upload/raw data proc return (); } + if ($type eq 'jpeg' && !$self->c->stash->{photo_gps}) { + # only store GPS for the first uploaded photo + $self->stash_gps_info($upload->tempname); + } + # Convert all images to JPEGs my %params = ( magick => 'JPEG' ); @@ -206,6 +211,31 @@ has ids => ( # Arrayref of $fileid tuples (always, so post upload/raw data proc }, ); +sub stash_gps_info { + my ($self, $filename) = @_; + + return unless can_run('jhead'); + + eval { + # run jhead on $filename and store in $stdout + my $stdout; + my $pid = open3(undef, $stdout, undef, 'jhead', $filename); + # parse lines like "GPS Latitude : N 51d 36m 52.32s + # GPS Longitude: W 0d 42m 27.24s" + my ($lat, $lon); + while (<$stdout>) { + if (/GPS Latitude : ([NS])\s+(\d+)d\s+(\d+)m\s+(\d+\.\d+)s/) { + $lat = $2 + $3/60 + $4/3600; + $lat = -$lat if $1 eq 'S'; + } elsif (/GPS Longitude: ([EW])\s+(\d+)d\s+(\d+)m\s+(\d+\.\d+)s/) { + $lon = $2 + $3/60 + $4/3600; + $lon = -$lon if $1 eq 'W'; + } + } + $self->c->stash->{photo_gps} = { lat => $lat, lon => $lon }; + }; +} + sub get_image_type { my ($self, $index) = @_; my $filename = $self->get_id($index); diff --git a/templates/web/base/around/postcode_form.html b/templates/web/base/around/postcode_form.html index 05f9190d09f..5ab8c776bd5 100644 --- a/templates/web/base/around/postcode_form.html +++ b/templates/web/base/around/postcode_form.html @@ -16,6 +16,17 @@
To continue draft enter its location.
Cancel
+