Geocoding Data
So far, you've been working with a sample database table that includesaddress information and positioning data (latitude and longitude).
But what if you're working with a database that doesn't have that positioning data? Most location-oriented databases only have address information such as street address, city, state, and zip code. Well, if you have address information or place names, you can use a Google Map "helper" web serviceto get the positioning data. Even partial address data, such as zip codes alone, can result in useful positioning data.
The way this works is: you send your address information to the helper service and it will return it with the positioning data (if it can find it) appended. Practically, what happens is that your datalayer gets two columns added to it, with the default names "Longitude" and "Latitude". This process is called "geocoding". The following exercise will show you how it's done.
- In Logi Studio, go to your _Settings definition and select the General element. Set the value for the Debugger Style attribute to DebuggerLinks.
- In your main report definition, collapse and remark your "gmHarleyDealers" Google Map element and add a new Google Map element to your definition, as shown above. Set its ID attribute to gmBikeShops and set its other attributes to match those of the remarked Google Map element.
- Beneath the new Google Map element, add a Map Markers element, as shown above. Set its ID attribute to mmBikeShops and set its other attributes to match those of the remarked Map Markers element.
- Beneath that element, add a DataLayer.XML element and set its attributes as shown above. It will use one of the .xml data files from the .zip file you downloaded earlier.
- Add a Geocode Columns element beneath the datalayer and set its attributes as shown above. If you're using a Connection.Google Maps element, enter its ID in the Connection ID attribute.
Also, notice that there are attributes for the Latitude and LongitudeColumnIDs; these default to "Latitude" and "Longitude", which also happen to be the names of the columns that the Google service appends to your data. Therefore, you can leave them blank for this exercise.
There's also a Place Data Column attribute. This is used if you don't have address data but instead have the names of points-of-interest, such as "Washington Monument" or "Brooklyn Bridge".
Save your changes and browse or preview the application. Your map of bicycle shops in Washington State should look like the image shown above.
Examine the Geocoded Data
Let's look at what the geocoding process actually did. Click the Debug icon in the bottom-right corner of your map page. Your map page will be replaced with the Debugger Trace page.
Look down the page and, in the Event column, find the Get DataLayer.XML entry, as shown above. A little further down, in the right-hand column, look for and click theView File Stream Data link, as shown above (the number of bytes may vary).
You should see the data in a table that was retrieved into your datalayer from the data file. Notice that two new columns, Latitude and Longitude, with positioning data have been added to each record by the Google Map service.
Return to the Debugger Trace page again and look down the Event column for ** WARNING ** messages. You can see here what happens in the trace when an address can't be geocoded. This maybe because of something extraneous in the data or you may have reached your allowed Google Map query limit.
Geocoding is a slick way of getting positioning data based on your address information. However, keep the following in mind:
- Each data record submitted for geocoding is considered a "transaction" and counts against your daily allotment as described in the terms of your license with Google.
- Geocoding takes time; the more records to be processed, the longer a delay the user faces so, for example, geocoding a huge database of addresses in real-time is not recommended.
- Errors in your address data not only take geocoding time but the failed attempts still count as transactions, so it's in your interest to have your address data be as clean and accurate as possible before geocoding.
- The Google service also "throttles" geocoding requests to keep itself from being overwhelmed and generally returns an "Error 620" if too many requests are received too quickly. The threshold is described in the terms of your license with Google.
Logi Info now includes the Connection.Nominatim element, for connections to a free, public, OpenStreetMap (OSM) Nominatim server for geographic data. More information is available in Datasource Connections.
The Include Condition Attribute
The Geocode Columns element has an Include Condition attribute. If the value of this attribute is left blank or contains a formula that evaluates to True, the element is utilized with the map. If the value evaluates to False, the element is ignored. This feature allows developers to dynamically switch between different sets of geocoding data.
Reverse Geocoding
Suppose you have the opposite location data situation from the one discussed above: you have the positioning data but not the address information. A typical use-case would be a mobile device app that "knows" its own GPS coordinates and needs to display the address.
The Reverse Geocode Columns element allows you to feed positioning data to the Google web service and retrieve address information. The web service will attempt to append and return data for the following columns into the datalayer: StreetNumber, StreetName, Locality, Sublocality, AreaLevel1, AreaLevel2, AreaLevel3, Country, Latitude, Longitude, and PostalCode.
Copyright © 2020 Logi Analytics, Inc. All Rights Reserved.