Skip to content

Instantly share code, notes, and snippets.

@dex4er
Last active December 17, 2015 06:28
Show Gist options
  • Select an option

  • Save dex4er/5565037 to your computer and use it in GitHub Desktop.

Select an option

Save dex4er/5565037 to your computer and use it in GitHub Desktop.
Geolocalization via Google (web form example)
#!/usr/bin/perl
use Mojolicious::Lite;
get '/' => 'main';
app->start;
__DATA__
@@ main.html.ep
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<%
use YAML::XS;
use Geo::Coder::Google;
use Encode 'decode_utf8';
%>
<head>
<title>Geo::Coder::Google</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {font-family: arial;}
</style>
<body>
<h1>Geo::Coder::Google</h1>
<%
my $location = param('location');
%>
<form method="GET">
<table>
<tr><td>Location: </td><td><input type="text" name="location" value="<%=$location%>" /></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Submit" /></td></tr>
</table>
</form>
% if ($location) {
<%
my $geocoder = Geo::Coder::Google->new(apiver => 3);
my $result = $geocoder->geocode(location => $location);
%>
<pre>
%= decode_utf8 Dump $result
</pre>
% }
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment