use strict; use LWP::Simple; # from CPAN use JSON qw( decode_json ); # from CPAN sub getLatLong($){ my ($address) = @_; my $format = "json"; #can also to 'xml' my $geocodeapi = "https://maps.googleapis.com/maps/api/geocode/"; my $url = $geocodeapi . $format . "?sensor=false&address=" . $address; my $json = get($url); my $d_json = decode_json( $json ); my $lat = $d_json->{results}->[0]->{geometry}->{location}->{lat}; my $lng = $d_json->{results}->[0]->{geometry}->{location}->{lng}; return ($lat, $lng); }