Radar provides comprehensive geocoding capabilities for iOS apps, including forward geocoding, reverse geocoding, IP geocoding, and address validation.
Forward Geocoding
Forward geocoding converts a human-readable address into geographic coordinates.
Basic Forward Geocoding
Radar. geocode ( address : "20 jay st brooklyn" ) { status, addresses in
if status == .success, let address = addresses ? . first {
print ( "Coordinate: \( address. coordinate ) " )
print ( "Formatted address: \( address. formattedAddress ?? "" ) " )
}
}
Forward Geocoding with Filters
You can filter geocoding results by layer type and country to get more precise results.
Radar. geocode (
address : "20 jay st brooklyn" ,
layers : [ "place" , "locality" ],
countries : [ "US" , "CA" ]
) { status, addresses in
if status == .success, let address = addresses ? . first {
print ( "Layer: \( address. layer ?? "" ) " )
print ( "Country: \( address. countryCode ?? "" ) " )
print ( "Coordinate: \( address. coordinate ) " )
}
}
Layer filters allow you to specify the type of result you want: place, address, locality, state, country, etc.
Reverse Geocoding
Reverse geocoding converts geographic coordinates into a human-readable address.
Basic Reverse Geocoding
Reverse geocode the device’s current location:
Radar. reverseGeocode { status, addresses in
if status == .success, let address = addresses ? . first {
print ( "Formatted address: \( address. formattedAddress ?? "" ) " )
print ( "City: \( address. city ?? "" ) " )
print ( "State: \( address. state ?? "" ) " )
print ( "Country: \( address. country ?? "" ) " )
}
}
Reverse Geocoding a Specific Location
let location = CLLocation ( latitude : 40.70390 , longitude : -73.98670 )
Radar. reverseGeocode ( location : location) { status, addresses in
if status == .success, let address = addresses ? . first {
print ( "Formatted address: \( address. formattedAddress ?? "" ) " )
print ( "Street: \( address. street ?? "" ) " )
print ( "Number: \( address. number ?? "" ) " )
print ( "Postal code: \( address. postalCode ?? "" ) " )
}
}
Reverse Geocoding with Layer Filters
let location = CLLocation ( latitude : 40.70390 , longitude : -73.98670 )
Radar. reverseGeocode (
location : location,
layers : [ "locality" , "state" ]
) { status, addresses in
if status == .success, let address = addresses ? . first {
print ( "City: \( address. city ?? "" ) " )
print ( "State: \( address. state ?? "" ) ( \( address. stateCode ?? "" ) )" )
}
}
IP Geocoding
IP geocoding converts the device’s IP address into an approximate location. This is useful for location-based content customization without requesting location permissions.
Radar. ipGeocode { status, address, proxy in
if status == .success, let address = address {
print ( "Country: \( address. countryCode ?? "" ) " )
print ( "City: \( address. city ?? "" ) " )
print ( "Is proxy: \( proxy ) " )
}
}
IP geocoding provides approximate location data at the city level. It should not be used for precise location-based features.
Address Validation
Validate and standardize addresses to ensure accuracy and completeness.
let address = RadarAddress ( from : [
"latitude" : 0 ,
"longitude" : 0 ,
"city" : "New York" ,
"stateCode" : "NY" ,
"postalCode" : "10003" ,
"countryCode" : "US" ,
"street" : "Broadway" ,
"number" : "841"
]) !
Radar. validateAddress ( address : address) { status, validatedAddress, verificationStatus in
if status == .success, let validatedAddress = validatedAddress {
print ( "Verification status: \( Radar. stringForVerificationStatus (verificationStatus) ) " )
print ( "Formatted address: \( validatedAddress. formattedAddress ?? "" ) " )
print ( "Plus4: \( validatedAddress. plus4 ?? "" ) " )
}
}
Verification Status Values
The RadarAddressVerificationStatus indicates the quality of the address match:
Verified
Complete match was made between the input data and a single record from the reference data.
Partially Verified
A partial match was made between the input data and a single record.
Ambiguous
More than one close reference data match was found.
Unverified
Unable to verify. The output fields will contain the input data.
Autocomplete
Autocomplete provides address suggestions as users type, sorted by relevance.
let origin = CLLocation ( latitude : 40.78382 , longitude : -73.97536 )
Radar. autocomplete (
query : "brooklyn" ,
near : origin,
layers : [ "locality" ],
limit : 10 ,
country : "US"
) { status, addresses in
if status == .success {
addresses ? . forEach { address in
print ( "Suggestion: \( address. formattedAddress ?? "" ) " )
}
}
}
Autocomplete with Mailable Filter
Filter results to only include addresses that can receive mail:
let origin = CLLocation ( latitude : 40.78382 , longitude : -73.97536 )
Radar. autocomplete (
query : "brooklyn" ,
near : origin,
layers : [ "address" ],
limit : 10 ,
country : "US" ,
mailable : true
) { status, addresses in
if status == .success {
addresses ? . forEach { address in
print ( "Mailable address: \( address. formattedAddress ?? "" ) " )
}
}
}
RadarAddress Properties
The RadarAddress object contains comprehensive address information:
Property Type Description coordinateCLLocationCoordinate2DThe location coordinate formattedAddressString?Formatted string representation countryString?Country name countryCodeString?Two-letter country code countryFlagString?Country flag emoji stateString?State or province name stateCodeString?State or province code postalCodeString?Postal or ZIP code cityString?City name boroughString?Borough name countyString?County name neighborhoodString?Neighborhood name streetString?Street name numberString?Street number unitString?Unit or apartment number plus4String?ZIP+4 extension addressLabelString?Address label placeLabelString?Place label layerString?Layer type (e.g., ‘place’, ‘address’) distanceNSNumber?Distance to search anchor in meters confidenceRadarAddressConfidenceConfidence level of result metadata[String: Any]?Additional metadata timeZoneRadarTimeZone?Time zone information categories[String]?Place categories
International Support
Radar’s geocoding APIs support addresses in over 100 countries worldwide. Use the countries parameter to filter results:
Radar. geocode (
address : "10 Downing Street" ,
layers : [ "address" ],
countries : [ "GB" ]
) { status, addresses in
// Handle results
}
For best results with international addresses, always specify the country code when it’s known.
Error Handling
All geocoding methods return a RadarStatus value indicating success or failure:
Radar. geocode ( address : query) { status, addresses in
switch status {
case . success :
print ( "Geocoding succeeded" )
case . errorNetwork :
print ( "Network error occurred" )
case . errorBadRequest :
print ( "Invalid request parameters" )
case . errorRateLimit :
print ( "Rate limit exceeded" )
default :
print ( "Error: \( Radar. stringForStatus (status) ) " )
}
}
Learn More
API Reference Explore the complete geocoding API reference
Places Learn about place search and categorization
Regions Understand region data model
Context Get comprehensive location context