30.4 google geocode
20210525
The geocode command takes a supplied address and produces specific location details.
$ ml geocode google [options] <address>
-b --google Generate Google Maps URL.
-g --google Generate Google Maps URL.
-m <int> --max=<int> Maximum number of matches.
-o --osm Generate Open Street Map URL.
-u --url Generate Open Street Map URL.
The output, separated by commas, consists of the latitude:longitude (north/south : east/west) location, a bounding box for the region (south latitude : west longitude : north latitude : east longitude), the confidence that the identified location is a match, a match code (good, ambiguous, uphierarchy), the entity type. The remaining output is the identified address (which will generally has commas within it). In summary, that is:
latitude:longitude,slat:wlong:nlat:elong,country,state,address
The address will likely have embedded commas and so to extract just the address:
$ ml geocode google 12 smith street canberra
-35.24:149.05,-35.25:149.05:-35.25:149.05,...,...,12 Smith St, Weetangera ACT 2614, Australia
$ ml geocode google 12 smith street canberra | cut -d, -f5-
12 Smith St, Weetangera ACT 2614, Australia
If the location is ambiguous then several rows will be returned, one for each possible location.
You can control the maximum number of matches (1-20) with the default
being 5, through -m
or --max=
.
Instead of providing the output described above you can request a URL
(universal resource locator) be returned. The URL is a link to a map
using either Open Street Map (preferred and default for -u
, --url
,
-o
or --osm``), Google Maps (
-bor
βgoogle), or Google Maps (
-gor
βgoogle`).
The following example splits the single line of output across several lines here for presentation. We geocode a specific locality:
This identifies it as:
-33.955379486083984:151.2429656982422,
-34.12508010864258:151.07327270507812:-33.78567886352539:151.41265869140625,
High,Ambiguous,PopulatedPlace,
Anzac Parade, NSW, Australia
The URL generation defaults to producing a URL link to Open Street Maps:
There are actually three matches for this address.
http://www.openstreetmap.org/?mlat=-33.9374938&mlon=151.2381616&zoom=18
You can copy and paste the URL into a browser. But suppose you want to display it directly into the browser:
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0