use strict;
use warnings;
use LWP::Simple; # from CPAN
use JSON qw( decode_json ); # from CPAN
#get my address
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://www.googleapis.com/geolocation/v1/geolocate?key=MY API KEY";
# set custom HTTP request header fields
my $req = new HTTP::Request POST =>( $server_endpoint);
$req->header('content-type' => 'application/json');
# add POST data to HTTP request body
my $post_data = '{"homeMobileCountryCode" : 235,
"homeMobileNetworkCode" : 77,
"radioType" : "gsm",
"carrier" : "BT Group",
"considerIp" : "true"}';
$req->content($post_data);
my $resp = $ua->request($req);
my $message = $resp->decoded_content;
print "Received Reply:$message\n";
####
Received Reply:{
"location": {
"lat": 53.4232611,
"lng": -1.0836272999999998
},
"accuracy": 901.0
}
####
my $lat = $message->{"location"}{"lat"};
####
Can't use string ("{
"location": {
"lat": 53.423"...) as a HASH ref while "strict refs" in use at etc.etc.