Xbasic

geocode_address Function

Syntax

dim result as P = geocode_address(C address [,C method [,C apiKey]])

Arguments

addressCharacter

The location to geocode in the format of a street address.

methodCharacter

Default = "Google". The web service to use for address geocoding. The geocode_address() function supports the following web services:

Method
Description
Google

Uses the Google Maps API. See https://developers.google.com/maps/documentation/geocoding/start#auth for more information about authentication, API keys, and quotas.

Nominatim

Uses OpenStreetMap data to encode the location. See http://nominatim.openstreetmap.org/ for more information.

apiKeyCharacter

Default = "". If the method used is "Google", this parameter is used to specify your Google API Key.

Returns

resultPointer

Returns an object with the following properties:

error_codeNumeric

The error code, if any error occurred. If no errors occurred, error_code will be zero.

error_textCharacter

If an error occurred, a message with information about the error. If no error occurred, error_text will be a blank string.

latCharacter

If the address was successfully geocoded, the latitude of the location. The lat property will not be available if gecode_address() fails.

lonCharacter

If the address was successfully geocoded, the longitude of the location. The lon property will not be available if geocode_address() fails.

Description

Geocode an address. Returns .lat and .lon. Also returns .error_code and .error_text. Address must be entered with commas between each part. e.g. 123 Main St., Boston, MA, 02116, USA. Method can be 'Nominatim' or 'Google'. Default is 'Google'

Example

dim location as p
location = geocode_address("1 Bellevue Ave, Newport, RI 02840")
? location
= error_code = 0
error_text = ""
lat = "41.4875748"
lon = "-71.3103195"

? location.lat
= "41.4875748"

? location.lon
= "-71.3103195"


? geocode_address("1 Unicorn Way, Providence, RI", "Nominatim")
= error_code = -1
error_text = "Invalid data in address."

See Also