HOW TO: Parse a LocationSensor's Current Address by SteveJG

HOW TO: Parse a LocationSensor’s Current Address by SteveJG

CurrentAddress

When an app asks the LocationSensor for the CurrentAddress, the LocationSensor retrieves the information Google provides from its database for a location in a csv format if there is any information in its database for the device’s current perceived location.

In the USA, the information provided is typically four (or possibly more) comma separated values.

For example in the USA:

Street Address,City,State plus zip code,Country parses to:

Street Address (if there is one) or another identifier.
City
State plus zip code
Country

1600 Pennsylvania Ave.,
Washington,
D.C. 20500,
USA

or something similar.

I was told by one user, the CurrentAddress is structured in his country like this:
Street number and name
Town name
County name
Postcode
Country

The results you get in the location information csv where you are located may only be:
Street
Town
Country

What information your device returns depends on the information available in Google’s Map database.

The “address” you receive might not always be the results you expect. The reported address also depends on the LocationSensor Accurracy value of the current satellite fix. What is reported for a street address might be the address of the building next door or the building across the street rather than where you think you should be. Why? Your GPS is not always reporting ‘precise’ geocoordinates. If the Accuracy is not a small value, your device isn’t necessarily where it ‘says’ it is.

There are multiple reasons why a user might not be able to get a street address. The information might be blocked in some countries, frequently an address is Not Available in rural areas (what is the address of a cotton field?) or in large cities without defined street information. Sometimes no address because the GPS fix is insufficient to provide that information or the device is not connected to the Internet. To use CurrentAddress, the device must have a network or WIFI connection. The CurrentAddress LocationSensor blocks ONLY work if your device is connected with WIFI or a Mobil Network because the LocationSensor must access an online Google database .

How to Parse the CurrentAddress or check it for specific information

Separate (parse the elements of the csv) to extract any piece of the information. Once you segregate a key element of the CurrentAddress, blocks can test whether your current location meets specific criteria.

One way to check for specific information is to use the

contains text
piece

from the Text block bin with an if statement. The tutorial example shows one way to check for the presence of specific information using a TextBox and a Button.


Enter the text you want to search for in the TextBox and press the button. It will tell you whether the specific text is present.

Use If…then statements to find information simply

If contains text Lynchburg piece LocationSensor1.CurrentAddress will flag any address in Lynchburg

If contains text 965 LocationSensor1.CurrentAddress will flag if “965” appears (will result in Boolean true if the CurrentAddress contains 965 but will also flag similar values like 1965 and 9654)

If contains text OH-131 might find Ohio route 131 depending on how Google reports it.

to filter the data.

If the information is not available for any reason (usually because there is no address as is the case outside of a city or town or because it was not possible for the mapping equipment to produce one), the request returns No address available

The example Project shows how to parse the CurrentAddress and two ways to extract or determine whether specific information is present in the CurrentAddress result. The example uses the LocationSensor (Map component is not needed).

How to use the example aia :
Press the Where Am I button You may have to do that several times while the GPS receiver finds where you are located. When that happens, you will see something similar to what is shown for Carrollton in the above graphic if it finds the searched text.

depending on what country you are in.

Type a City name in the Text field adjacent to the Use the Is this in the address? button and press the Button to see if specific information is available in the CurrentAddress Remember to type something in the TextBox (perhaps the name of your city or town?) before using the Button.

The Blocks

Regards,
Steve

CurrentAddressParsedExample.aia (5.4 KB)

7 Likes

thumbsup2

Very nice!

(added to FAQ)