Skip to content

Commit

Permalink
display wifi access points on the map
Browse files Browse the repository at this point in the history
  • Loading branch information
nst committed Oct 31, 2010
1 parent 880ba9a commit 7dd3329
Show file tree
Hide file tree
Showing 22 changed files with 9,410 additions and 704 deletions.
2 changes: 1 addition & 1 deletion Classes/SPImageAnnotation.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @implementation SPImageAnnotation
@synthesize path;
@synthesize coordinate;

+ (SPImageAnnotation *) annotationWithCoordinate:(CLLocationCoordinate2D)coord date:(NSDate *)date path:(NSString *)path {
+ (SPImageAnnotation *)annotationWithCoordinate:(CLLocationCoordinate2D)coord date:(NSDate *)date path:(NSString *)path {
SPImageAnnotation *annotation = [[SPImageAnnotation alloc] init];
annotation.coordinate = coord;
annotation.path = path;
Expand Down
2 changes: 1 addition & 1 deletion Classes/SPMapVC.h → Classes/SPImageMapVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@class SPImageVC;

@interface SPMapVC : UIViewController <MKMapViewDelegate> {
@interface SPImageMapVC : UIViewController <MKMapViewDelegate> {
NSArray *annotations;

IBOutlet MKMapView *mapView;
Expand Down
6 changes: 2 additions & 4 deletions Classes/SPMapVC.m → Classes/SPImageMapVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// Licensed under GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.txt
//

#import "SPMapVC.h"
#import "SPImageMapVC.h"
#import "SPImageVC.h"

@implementation SPMapVC
@implementation SPImageMapVC

@synthesize annotations;

Expand Down Expand Up @@ -92,11 +92,9 @@ - (void)viewDidUnload {
self.annotations = nil;
}


- (void)dealloc {
[annotations release];
[super dealloc];
}


@end
4 changes: 2 additions & 2 deletions Classes/SPSourceLocationTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#import "SPSourceLocationTVC.h"
#import <CoreLocation/CoreLocation.h>
#import "SPMapVC.h"
#import "SPImageMapVC.h"
#import "SPImageAnnotation.h"

@implementation SPSourceLocationTVC
Expand All @@ -24,7 +24,7 @@ @implementation SPSourceLocationTVC

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0 && indexPath.row == 0 && cachedLocationFromMaps) {
SPMapVC *mapVC = [[SPMapVC alloc] initWithNibName:@"SPMapVC" bundle:[NSBundle mainBundle]];
SPImageMapVC *mapVC = [[SPImageMapVC alloc] initWithNibName:@"SPImageMapVC" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:mapVC animated:YES];
SPImageAnnotation *annotation = [SPImageAnnotation annotationWithCoordinate:cachedLocationFromMaps.coordinate date:nil path:nil];
[mapVC addAnnotation:annotation];
Expand Down
6 changes: 3 additions & 3 deletions Classes/SPSourcePhotosTVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

#import "SPSourceTVC.h"

@class SPMapVC;
@class SPImageMapVC;
@class SPImageVC;

@interface SPSourcePhotosTVC : SPSourceTVC {
NSMutableArray *coordinates;
NSMutableArray *annotations;

IBOutlet SPMapVC *mapVC;
IBOutlet SPImageMapVC *mapVC;
IBOutlet SPImageVC *imageVC;
}

@property (nonatomic, retain) NSMutableArray *annotations;
@property (nonatomic, retain) NSMutableArray *coordinates;
@property (nonatomic, retain) SPMapVC *mapVC;
@property (nonatomic, retain) SPImageMapVC *mapVC;
@property (nonatomic, retain) SPImageVC *imageVC;

@end
2 changes: 1 addition & 1 deletion Classes/SPSourcePhotosTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <CoreLocation/CoreLocation.h>
#import "SPSourcePhotosTVC.h"
#import "UIImage+GPS.h"
#import "SPMapVC.h"
#import "SPImageMapVC.h"
#import "SPImageVC.h"
#import "SPImageAnnotation.h"

Expand Down
10 changes: 9 additions & 1 deletion Classes/SPSourceWifiTVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
#import "SPSourceTVC.h"
#import "OUILookupTool.h"

@interface SPSourceWifiTVC : SPSourceTVC <OUILookupToolDelegate> {
@class SPWifiMapVC;

@interface SPSourceWifiTVC : SPSourceTVC <OUILookupToolDelegate> {
NSMutableArray *annotations;
NSMutableArray *accessPoints;
IBOutlet SPWifiMapVC *mapVC;
}

@property (nonatomic, retain) NSMutableArray *annotations;
@property (nonatomic, retain) NSMutableArray *accessPoints;
@property (nonatomic, retain) SPWifiMapVC *mapVC;

@end
56 changes: 53 additions & 3 deletions Classes/SPSourceWifiTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,30 @@

#import "SPSourceWifiTVC.h"
#import "OUILookupTool.h"
#import "SPWifiMapVC.h"
#import "SPWifiAnnotation.h"
#import "SPCell.h"

@implementation SPSourceWifiTVC

@synthesize annotations;
@synthesize accessPoints;
@synthesize mapVC;

- (void)loadData {

//[OUILookupTool lookupBSSID:@"0:30:bd:97:7:72" delegate:self];

if(contentsDictionaries) return;

UIBarButtonItem *mapButton = [[UIBarButtonItem alloc] initWithTitle:@"Map" style:UIBarButtonItemStylePlain target:self action:@selector(mapButtonClicked:)];
super.navigationItem.rightBarButtonItem = mapButton;

self.contentsDictionaries = [NSMutableArray array];

self.annotations = [NSMutableArray array];

self.accessPoints = [NSMutableArray array];

NSString *path = @"/Library/Preferences/SystemConfiguration/com.apple.wifi.plist";
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
Expand All @@ -28,23 +42,59 @@ - (void)loadData {
if(!a) return;

for(NSDictionary *d in a) {
[OUILookupTool locateWifiAccessPoint:d delegate:self];
NSMutableDictionary *md = [NSMutableDictionary dictionaryWithDictionary:d];

[OUILookupTool locateWifiAccessPoint:md delegate:self];

NSString *name = [d valueForKey:@"SSID_STR"];

NSData *joined = [d valueForKey:@"lastJoined"];
NSData *autoJoined = [d valueForKey:@"lastAutoJoined"];
NSDate *joined = [md valueForKey:@"lastJoined"];
NSDate *autoJoined = [md valueForKey:@"lastAutoJoined"];

NSString *date = [NSString stringWithFormat:@"%@", autoJoined ? autoJoined : joined];

[contentsDictionaries addObject:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject:name] forKey:date]];
[accessPoints addObject:md];
}
}

- (void)mapButtonClicked:(id)sender {
mapVC.annotations = annotations;
[self.navigationController pushViewController:mapVC animated:YES];
}

- (void)dealloc {
[accessPoints release];
[annotations release];
[mapVC release];
[super dealloc];
}

#pragma mark OUILookupTool

- (void)OUILookupTool:(OUILookupTool *)ouiLookupTool didLocateAccessPoint:(NSDictionary *)ap {
//NSLog(@"-- %@", ap);

[accessPoints addObject:ap];

SPWifiAnnotation *annotation = [SPWifiAnnotation annotationWithAccessPoint:ap];

if(annotation) [annotations addObject:annotation];
}

#pragma mark UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSDictionary *ap = [accessPoints objectAtIndex:indexPath.section];

SPWifiAnnotation *annotation = [SPWifiAnnotation annotationWithAccessPoint:ap];

if(annotation == nil) return;

mapVC.annotations = [NSArray arrayWithObject:annotation];

[self.navigationController pushViewController:mapVC animated:YES];
}

@end
28 changes: 28 additions & 0 deletions Classes/SPWifiAnnotation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// SPWifiAnnotation.h
// SpyPhone
//
// Created by Nicolas Seriot on 10/31/10.
// Copyright 2010 IICT. All rights reserved.
//

#import <MapKit/MapKit.h>

@protocol MKAnnotation;

@interface SPWifiAnnotation : NSObject <MKAnnotation> {
NSDictionary *accessPoint;
CLLocationCoordinate2D coordinate;
}

@property (nonatomic, retain) NSDictionary *accessPoint;
@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;

+ (SPWifiAnnotation *)annotationWithAccessPoint:(NSDictionary *)d;

- (NSString *)annotationViewIdentifier;

- (NSString *)title;
- (NSString *)subtitle;

@end
51 changes: 51 additions & 0 deletions Classes/SPWifiAnnotation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// SPWifiAnnotation.m
// SpyPhone
//
// Created by Nicolas Seriot on 10/31/10.
// Copyright 2010 IICT. All rights reserved.
//

#import "SPWifiAnnotation.h"


@implementation SPWifiAnnotation

@synthesize coordinate;
@synthesize accessPoint;

- (NSString *)title {
return [accessPoint valueForKey:@"SSID_STR"];
}

- (NSString *)subtitle {
NSDate *joined = [accessPoint valueForKey:@"lastJoined"];
NSDate *autoJoined = [accessPoint valueForKey:@"lastAutoJoined"];

NSDate *date = autoJoined ? autoJoined : joined;

return [date description];
}

+ (SPWifiAnnotation *)annotationWithAccessPoint:(NSDictionary *)ap {
NSString *latitude = [ap valueForKeyPath:@"location.latitude"];
NSString *longitude = [ap valueForKeyPath:@"location.longitude"];

if(latitude == nil || longitude == nil) return nil;

SPWifiAnnotation *annotation = [[SPWifiAnnotation alloc] init];
annotation.accessPoint = ap;
annotation.coordinate = CLLocationCoordinate2DMake([latitude doubleValue], [longitude doubleValue]);;
return [annotation autorelease];
}

- (void)dealloc {
[accessPoint release];
[super dealloc];
}

- (NSString *)annotationViewIdentifier {
return [accessPoint valueForKey:@"BSSID"];
}

@end
24 changes: 24 additions & 0 deletions Classes/SPWifiMapVC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// SPWifiMapVC.h
// SpyPhone
//
// Created by Nicolas Seriot on 10/31/10.
// Copyright 2010 IICT. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface SPWifiMapVC : UIViewController {
NSArray *annotations;

IBOutlet MKMapView *mapView;
}

@property (nonatomic, retain) NSArray *annotations;

//- (void)addAnnotation:(id <MKAnnotation>)annotation;

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;

@end
78 changes: 78 additions & 0 deletions Classes/SPWifiMapVC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// SPWifiMapVC.m
// SpyPhone
//
// Created by Nicolas Seriot on 10/31/10.
// Copyright 2010 IICT. All rights reserved.
//

#import "SPWifiMapVC.h"


@implementation SPWifiMapVC

@synthesize annotations;

//- (void)setAnnotations:(NSArray *)someAnnotations {
// [mapView removeAnnotations:mapView.annotations];
//
// [annotations autorelease];
// annotations = [someAnnotations retain];
//
// [mapView addAnnotations:annotations];
//}

- (void)loadView {
[super loadView];

self.title = @"Wifi Map";
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[mapView removeAnnotations:annotations];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

[mapView addAnnotations:annotations];

id <MKAnnotation>annotation = [annotations lastObject];
MKCoordinateSpan span = MKCoordinateSpanMake(0.03, 0.03);
MKCoordinateRegion region = [mapView regionThatFits:MKCoordinateRegionMake(annotation.coordinate, span)];

[mapView setRegion:region animated:NO];

if([annotations count] == 1) [mapView selectAnnotation:[annotations lastObject] animated:YES];
}

- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation {

if([annotation isKindOfClass:[MKUserLocation class]]) return nil;

NSString *annID = @"SPWifiAnnotation";
MKAnnotationView *av = [aMapView dequeueReusableAnnotationViewWithIdentifier:annID];

if(av == nil) {
av = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annID] autorelease];
av.canShowCallout = YES;
}
return av;
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)dealloc {
[annotations release];
[super dealloc];
}

@end
Loading

0 comments on commit 7dd3329

Please sign in to comment.