Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Tan authored and Jerome Tan committed May 9, 2016
2 parents e959fd0 + deb878e commit 368b04e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,15 @@
# Change Log

## [1.1.1](https://github.com/JeromeTan1997/LocationPicker/releases/tag/1.1.1) (2016-05-09)

#### Enhancements

- Support offline location for `LocationItem`

#### Bug fixes

- Fix a typo in demo

## [1.1.0](https://github.com/JeromeTan1997/LocationPicker/releases/tag/1.1.0) (2016-05-08)

#### Enhancements
Expand Down
21 changes: 16 additions & 5 deletions LocationPicker/LocationItem.swift
Expand Up @@ -67,10 +67,14 @@ public class LocationItem: NSObject, NSCoding {
}

/// The coordinate of the location. A reference to `MKMapItem` object's property `placemark.coordinate` and converted to tuple.
public var coordinate: (latitude: Double, longitude: Double) {
public var coordinate: (latitude: Double, longitude: Double)? {
get {
let coordinate = mapItem.placemark.coordinate
return coordinateTupleFromObject(coordinate)
if CLLocationCoordinate2DIsValid(coordinate) {
return coordinateTupleFromObject(coordinate)
} else {
return nil
}
}
}

Expand All @@ -94,7 +98,7 @@ public class LocationItem: NSObject, NSCoding {

public override var hashValue: Int {
get {
if CLLocationCoordinate2DIsValid(coordinateObjectFromTuple(coordinate)) {
if let coordinate = coordinate {
return "\(coordinate.latitude), \(coordinate.longitude)".hashValue
} else {
return mapItem.name?.hashValue ?? "".hashValue
Expand All @@ -120,6 +124,13 @@ public class LocationItem: NSObject, NSCoding {
self.mapItem = MKMapItem(placemark: placeMark)
}

public init(locationName: String) {
// Create map item with name and invalid placemark coordinate (since placemark is not optional in MKMapItem)
let placeMark = MKPlacemark(coordinate: kCLLocationCoordinate2DInvalid, addressDictionary: nil)
self.mapItem = MKMapItem(placemark: placeMark)
self.mapItem.name = locationName
}

public override func isEqual(object: AnyObject?) -> Bool {
return object?.hashValue == hashValue
}
Expand All @@ -134,8 +145,8 @@ public class LocationItem: NSObject, NSCoding {
}

public func encodeWithCoder(coder: NSCoder) {
coder.encodeObject(coordinate.latitude, forKey: "latitude")
coder.encodeObject(coordinate.longitude, forKey: "longitude")
coder.encodeObject(mapItem.placemark.coordinate.latitude, forKey: "latitude")
coder.encodeObject(mapItem.placemark.coordinate.longitude, forKey: "longitude")
coder.encodeObject(addressDictionary, forKey: "addressDictionary")
}

Expand Down
12 changes: 4 additions & 8 deletions LocationPicker/LocationPicker.swift
Expand Up @@ -758,11 +758,8 @@ public class LocationPicker: UIViewController, UISearchBarDelegate, UITableViewD
MKLocalSearch(request: localSearchRequest).startWithCompletionHandler({ (localSearchResponse, error) -> Void in
guard error == nil,
let localSearchResponse = localSearchResponse where localSearchResponse.mapItems.count > 0 else {
// Create map item with name and invalid placemark coordinate (since placemark is not optional in MKMapItem)
let placemark = MKPlacemark(coordinate: kCLLocationCoordinate2DInvalid, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = searchText
self.searchResultLocations = [LocationItem(mapItem: mapItem)]
let locationItem = LocationItem(locationName: searchText)
self.searchResultLocations = [locationItem]
self.tableView.reloadData()
return
}
Expand Down Expand Up @@ -948,9 +945,8 @@ public class LocationPicker: UIViewController, UISearchBarDelegate, UITableViewD
private func selectLocationItem(locationItem: LocationItem) {
selectedLocationItem = locationItem
searchBar.text = locationItem.name
let coordinate = coordinateObjectFromTuple(locationItem.coordinate)
if CLLocationCoordinate2DIsValid(coordinate) {
showMapViewWithCenterCoordinate(coordinate, WithDistance: longitudinalDistance)
if let coordinate = locationItem.coordinate {
showMapViewWithCenterCoordinate(coordinateObjectFromTuple(coordinate), WithDistance: longitudinalDistance)
} else {
closeMapView()
}
Expand Down
2 changes: 1 addition & 1 deletion LocationPickerDemo/LocationPickerDemo/ViewController.swift
Expand Up @@ -111,7 +111,7 @@ class ViewController: UIViewController, LocationPickerDelegate, LocationPickerDa
return historyLocationList.reverse()[index]
}

func commitHistoryLocationDeletion(locationItem: LocationItem) {
func commitAlternativeLocationDeletion(locationItem: LocationItem) {
historyLocationList.removeAtIndex(historyLocationList.indexOf(locationItem)!)
}

Expand Down
2 changes: 1 addition & 1 deletion LocationPickerViewController.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "LocationPickerViewController"
s.version = "1.1.0"
s.version = "1.1.1"
s.summary = "A ready for use and fully customizable location picker for your app."

s.homepage = "https://github.com/JeromeTan1997/LocationPicker"
Expand Down
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -99,7 +99,7 @@ let package = Package(
name: "Your Project Name",
targets: [],
dependencies: [
.Package(url: "https://github.com/JeromeTan1997/LocationPicker.git", versions: "1.1.0" ..< Version.max)
.Package(url: "https://github.com/JeromeTan1997/LocationPicker.git", versions: "1.1.1" ..< Version.max)
]
)
```
Expand Down Expand Up @@ -426,7 +426,7 @@ The hash value of `LocationItem` is `"\(coordinate.latitude), \(coordinate.longi
| Property name | Type | Target | Remark |
| ------------- |:----:| ------ | ------ |
| name | String | mapItem.name | The name of the location |
| coordinate | (latitude: Double, longitude: Double) | mapItem.placemark.coordinate | The coordinate of the location and converted to tuple |
| coordinate | (latitude: Double, longitude: Double)? | mapItem.placemark.coordinate | The coordinate of the location and converted to tuple. If the user is offline or there is no search result, this property will be `nil` |
| addressDictionary | [NSObject: AnyObject]? | mapItem.placemark.addressDictionary | The address dictionary of the location |
| formattedAddressString | String? | addressDictionary?["FormattedAddressLines"] | The address text formatted according to user's region |

Expand All @@ -444,6 +444,10 @@ You can also initialize with the coordinate and address dictionary.

If you don't want to store `LocationItem` objects as `NSData`, you can just store the coordinate and address dictionary, and use this method to initialize.

#### `init(locationName: String)`

A location can be created with only a name. In this case, the value of property `coordinate` would be `nil`.

## Change Log

[CHANGELOG.md](https://github.com/JeromeTan1997/LocationPicker/blob/master/CHANGELOG.md)
Expand Down

0 comments on commit 368b04e

Please sign in to comment.