Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
747B6506173EFB5900DECD54 /* LocationPickerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 747B6503173EFB5900DECD54 /* LocationPickerView.m */; };
747B6507173EFB5900DECD54 /* UIImage+Icons.m in Sources */ = {isa = PBXBuildFile; fileRef = 747B6505173EFB5900DECD54 /* UIImage+Icons.m */; };
747B6509173F35A900DECD54 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 747B6508173F35A900DECD54 /* MapKit.framework */; };
747B650C173F388500DECD54 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 747B650B173F388500DECD54 /* SecondViewController.m */; };
F5760A121B0266AD0002CBC2 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5760A111B0266AD0002CBC2 /* CoreLocation.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -46,15 +46,15 @@
747B6504173EFB5900DECD54 /* UIImage+Icons.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Icons.h"; sourceTree = "<group>"; };
747B6505173EFB5900DECD54 /* UIImage+Icons.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Icons.m"; sourceTree = "<group>"; };
747B6508173F35A900DECD54 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
747B650A173F388500DECD54 /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = "<group>"; };
747B650B173F388500DECD54 /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = "<group>"; };
F5760A111B0266AD0002CBC2 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
747B64D8173EFB4400DECD54 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F5760A121B0266AD0002CBC2 /* CoreLocation.framework in Frameworks */,
747B6509173F35A900DECD54 /* MapKit.framework in Frameworks */,
747B64DF173EFB4400DECD54 /* UIKit.framework in Frameworks */,
747B64E1173EFB4400DECD54 /* Foundation.framework in Frameworks */,
Expand Down Expand Up @@ -86,6 +86,7 @@
747B64DD173EFB4400DECD54 /* Frameworks */ = {
isa = PBXGroup;
children = (
F5760A111B0266AD0002CBC2 /* CoreLocation.framework */,
747B6508173F35A900DECD54 /* MapKit.framework */,
747B64DE173EFB4400DECD54 /* UIKit.framework */,
747B64E0173EFB4400DECD54 /* Foundation.framework */,
Expand All @@ -102,8 +103,6 @@
747B64F6173EFB4400DECD54 /* MainStoryboard.storyboard */,
747B64F9173EFB4400DECD54 /* ViewController.h */,
747B64FA173EFB4400DECD54 /* ViewController.m */,
747B650A173F388500DECD54 /* SecondViewController.h */,
747B650B173F388500DECD54 /* SecondViewController.m */,
747B64E5173EFB4400DECD54 /* Supporting Files */,
);
path = "LocationPickerView-Demo";
Expand Down Expand Up @@ -206,7 +205,6 @@
747B64FB173EFB4400DECD54 /* ViewController.m in Sources */,
747B6506173EFB5900DECD54 /* LocationPickerView.m in Sources */,
747B6507173EFB5900DECD54 /* UIImage+Icons.m in Sources */,
747B650C173F388500DECD54 /* SecondViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -329,6 +327,7 @@
747B6500173EFB4400DECD54 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down

This file was deleted.

This file was deleted.

60 changes: 56 additions & 4 deletions LocationPickerView-Demo/LocationPickerView-Demo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

#import <MapKit/MapKit.h>
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController ()

@property (nonatomic,strong)NSArray *cities;
@property (nonatomic,strong)NSMutableArray *selectedItems;
@property (nonatomic,strong)NSMutableDictionary *annotations;
@end

@implementation ViewController
Expand Down Expand Up @@ -52,6 +56,10 @@ - (void)viewDidLoad
*/

[self.view addSubview:self.locationPickerView];

self.cities = [NSArray arrayWithObjects:@"Colombo",@"London",@"New York",@"Cardiff",@"Moscow",@"Beijing",@"Tokyo",@"Melbourne",@"Zurich",@"Berlin",@"Salzburg",@"Helsinki",@"Seoul",@"Pyong Yang",@"Perth",@"Brisbane",@"Oslo",@"Sydney",@"Vienna",@"Cairo",@"Rio De Janeiro",@"Nairobi", nil];
self.selectedItems = [[NSMutableArray alloc]init];
self.annotations = [[NSMutableDictionary alloc]init];
}

- (void)didReceiveMemoryWarning
Expand All @@ -64,7 +72,7 @@ - (void)didReceiveMemoryWarning

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
return [self.cities count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Expand All @@ -74,15 +82,31 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reusable"];
}

cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
cell.textLabel.text = [self.cities objectAtIndex:indexPath.row];


cell.textLabel.text = [self.cities objectAtIndex:indexPath.row];
if ([self.selectedItems containsObject:[self.cities objectAtIndex:indexPath.row]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self performSegueWithIdentifier:@"Second" sender:self];

if ([self.selectedItems containsObject:[self.cities objectAtIndex:indexPath.row]]) {
[self.selectedItems removeObject:[self.cities objectAtIndex:indexPath.row]];
[self removeLocation:[self.cities objectAtIndex:indexPath.row]];
}else {
[self.selectedItems addObject:[self.cities objectAtIndex:indexPath.row]];
[self setLocation:[self.cities objectAtIndex:indexPath.row]];
}

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down Expand Up @@ -134,5 +158,33 @@ - (void)locationPicker:(LocationPickerView *)locationPicker tableViewDidLoad:(UI
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}

#pragma mark -
- (void)setLocation:(NSString *)location{

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
__weak typeof(self) weakSelf = self;
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

MKCoordinateRegion region = weakSelf.locationPickerView.mapView.region;
region.center = [(CLCircularRegion *)placemark.region center];
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;

[weakSelf.locationPickerView.mapView setRegion:region animated:YES];
[weakSelf.locationPickerView.mapView addAnnotation:placemark];

[self.annotations setObject:placemark forKey:location];
}
}
];
}

- (void)removeLocation:(NSString *)location{

[self.locationPickerView.mapView removeAnnotation:[self.annotations objectForKey:location]];
}
@end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MKMapView + UITableView + Parallax scrolling. Provides a framework for building
This view is useful for when a list of scrollable, selectable locations need to be shown along with their locations on map. A search bar can easily be added for searching or filtering.

<p align="center">
<img src="github-images/location-picker.gif"/></td>
<img src="github-images/locationPicker.png"/></td>
</p>

## Install
Expand Down
Binary file added github-images/locationPicker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.