Geocoding is the process of transforming textual address to a location or a geographic identity, basically same as Address Search
Reverse geocoding converts geographic location coordinates back to an address.
CARTO Mobile SDK supports both geocoding and reverse geocoding and both are available in online and offline modes. Offline geocoding requires that you download special offline data package through Package Manager, see chapter above for more about this.
Mobile SDK supports the following geocoding features:
Free-form text input. A specific order of the address components is not assumed.
Autocomplete support, get results while typing.
Location bias for geocoding. SDK will prefer the addresses close to specified location.
Localization of addresses. The geocoding addresses will be returned in specified language, if possible.
Online Geocoding
CARTO Online geocoding is an API wrapper to external online service provider. CARTO does not currently provide own service, so SDK has built-in support for Mapbox, TomTom and Pelias (former MapZen) online geocoding APIs. For all these services you need either a token or an API key from the service provider, or you can use custom URL to connect to your on-premises instance.
The following sample uses TomTom service, but Mapbox and Pelias services can be used instead by replacing TomTomOnlineGeocodingService with PeliasOnlineGeocodingService or MapboxOnlineGeocodingService.
The resulting GeocodingResultVector is just a list of results, you can loop through it as you would with any other list. From your GeocodingResult objects, you can find name, locality, country etc. properties and display them to the user.
Note: As the service is making web requests, then you should NOT call CalculateAddresses from your UI thread.
Like online geocoding, online reverse geocoding is available through multiple online service providers. SDK has built-in support for Mapbox, TomTom and Pelias (former MapZen) reverse geocoders.
For these services you need to get a token or an API key from the service provider, or use custom URL as optional method for on-premises servers.
The following sample uses TomTom service, but Mapbox and Pelias services can be used instead by replacing TomTomOnlineReverseGeocodingService with PeliasOnlineReverseGeocodingService or MapboxOnlineReverseGeocodingService.
Note: As the service is making web requests, then you should NOT call CalculateAddresses from your UI thread.
CARTO Mobile SDK also supports offline geocoding and reverse geocoding, In order to geocode offline, you must first download the required country geocoding data packages.
Note: You will not be able to geocode without downloaded data packages, and the geocoding packages are different from Offline Map packages, do not mix them up !
The list of country packages for geocoding is the same as other offline maps. See Offline Map Packages for the full list of offline packages. The download size of an offline geocoding package is somewhat smaller (10-40%) than the size of the corresponding offline map package.
First, you need to initialize a package manager and a listener to download packages, and then download package for the country what you need. See PackageManager page above to find more about offline packages. If relevant package(s) are downloaded and (reverse) geocoding service is ready, you can start geocoding:
Use your PackageManager within PackageManagerReverseGeocodingService or PackageManagerGeocodingService as given in sample below. Then define the GeocodingRequest and start geocoding using service’s calculateAddresses and read response as GeocodingResult, just as in Online Geocoding and Reverse Geocoding samples above.