Check if CLPlacemark's name is a street address

657 views Asked by At

Is it possible to check whether or not a CLPlacemark's name is a street address?

I would like to display the name if it is a shopping center, theme park, school, or something else interesting, but not if it is a street address.

I was thinking about using a regex such as this to check if the name is a street address

^\d+ ([a-zA-Z0-9'-] ?)+$

But I feel like this won't always work, especially in other countries.

Is there any way to check if a CLPlacemark's name is a street address, like checking the size of the placemark, or will I have to use a third-party library?

2

There are 2 answers

1
Dan Nichols On BEST ANSWER

Try checking the name against the CLPlacemark's thoroughfare (street) and subThoroughfare (street number).

var placemark: CLPlacemark
if placemark.name.rangeOfString(placemark.thoroughfare) != nil
    && placemark.name.rangeOfString(placemark.subThoroughfare) != nil {
        println("Name is likely the same as address")
} else {
    println("Name is distinct from street address")
}
2
Charlie On

There is also a CLPlacemark property "AreaOfInterest" that you can check. This is often tagged for areas that have a general category, like airports, shopping centers, schools, museums, etc.

Since you are wanting to remove anything that essentially isn't an area of interest, maybe this field will do the work for you?