30.4 bing geocode

20210525

The geocode command takes a supplied address and produces specific location details.

$ ml geocode bing [options] <address>
     -b            --bing               Generate Bing 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 (generally including commas):

latitude:longitude,slat:wlong:nlat:elong,confidence,code,etype,address

For example:

ml geocode bing --max=1 anzac parade

The output is as below, though unlike here the actual output will be on a single line for each location identified. Multiple locations are identified when the location is ambiguous.

-33.955379486083984:151.2429656982422,
-34.12508010864258:151.07327270507812:-33.78567886352539:151.41265869140625,
High,Ambiguous,PopulatedPlace,
Anzac Parade, NSW, Australia

We control the maximum number of matches (1-20) using -m or --max= (the default is 5).

A URL (universal resource locator) can be requested for a map using either Open Street Map (preferred and the default for -u, --url, -o or --osm), Bing Maps (-b or --bing), or Google Maps (-g or --google).

ml geocode bing --url anzac parade

There are actually three matches for this address.

http://www.openstreetmap.org/?mlat=-33.955379486083984&mlon=151.2429656982422&zoom=12
http://www.openstreetmap.org/?mlat=-35.2863883972168&mlon=149.14389038085938&zoom=12
http://www.openstreetmap.org/?mlat=-35.2863883972168&mlon=149.14389038085938&zoom=12

You can copy and paste the URL into a browser or extract, for example, the second match above and browse directly to that:

xdg-open `ml geocode --url bing anzac parade | sed '2q;d'`

The sed command (the stream editor) matches the second line sent through the pipeline (2 is the address), prints it by default, and then quits (q). Other lines before 2 (i.e., just 1) are processed by the second sed command d (deleted), as otherwise, by default, they would be printed. Simple sed commands can be separated by the semicolon (;). Because we quit after the second line, no further lines get printed. Thus this command extracts the second line from standard input. Change 2 to 3 in the sed, for example, to get the third line (the third match from the Bing maps command).



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