#!/data/data/com.google.ase/perl/perl use strict; use warnings; use Android; use Data::Dumper; my $droid = Android->new; print "\n"; print "Starting GPS, and locating for 15 seconds..\n"; $droid->startLocating(); sleep 15; my $location; for ( 1 .. 3 ) { $location = $droid->readLocation() || $droid->getLastKnownLocation(); last if defined $location and !defined $location->{error}; print "Problems fetching location, sleeping 3 seconds..\n"; sleep 3; } $droid->stopLocating(); print "Location results(debug):", Dumper($location); die "Could not gather location." if ( !defined $location ); die "Error reading location: ", $location->{error} if defined $location->{error}; die "No latitude found" unless defined $location->{result}{network}{latitude}; die "No longitude found" unless defined $location->{result}{network}{longitude}; my $latitude = $location->{result}{network}{latitude}; my $longitude = $location->{result}{network}{longitude}; print "Latitude: $latitude\n"; print "longitude: $longitude\n"; my $geocode = $droid->geocode($latitude,$longitude); print "Geocoding results: ", Dumper($geocode); die "Error geocoding: ", $geocode->{error} if defined $geocode->{error}; my $result = join("\n",map { "AREA:\n" . "Admin area: " . $_->{admin_area} . "\n" . "Country code: " . $_->{country_code} . "\n" . "Country name: " . $_->{country_name} . "\n" . "Feature name: " . $_->{feature_name} . "\n" . "Locality: " . $_->{locality} . "\n" . "Postal code: " . $_->{postal_code} . "\n" . "Thoroughfare: " . $_->{thoroughfare} . "\n" . "Subadmin area:" . $_->{sub_admin_area} . "\n" . "" } grep {defined} map { $geocode->{result}[$_] } 0..1); $droid->speak("You are in " . $geocode->{result}[0]{locality}); print $result; $droid->dialogCreateAlert($result); $droid->dialogShow();