There is this from another poster. (jpgunter)https://stackoverflow.com/users/1857927/jpgunter
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);
}
It looks to be doing what I want, but... is anyone able to explain where I put the address to run it and where does the output go?
I have to run through about 5000 cities from another file for a 'non-scholastic' project I am working on and obviously the thought of doing manually is horrific. I also have only done minimal perl in the last 7 years so absolutely any help would be great. I already have LWP 6.04 and JSON 2.53 installed. if I could use an input file, rotate this through (with postcodes where it shows it). That line would be on... "formatted_address" : "Geelong West VIC 3218, Australia", Just not sure how to get the 3218 there.
The original post is here... Get the Latitude and Longitude of an address using perl and Google's Geocode API