Iphone developer advance location based
- 2. 犖犖о顕犖÷牽犖項犖犖劇犖幡犖迦犖犖朽犖犢犖迦攻釣犢犖
- Objective-C for iPhone Programming
- Basic UI iPhone Programming
- Model View Controller
- XML Parser
- Property List / SQLite
Monday, March 26, 12
- 3. 犢犖犖劇犖犖犖迦犖犖犖ム険犖犖犖項犖 Location Based Application
Core Location
- CLLocationManager
CLLocationManagerDelegate
CLLocation
- CLLocationCoordinate2D
CLLocationDistance
MapKit
- MKMapView
MKMapViewDelegate
MKCoordinateRegion
MKCoordinateSpan
- MKReverseGeocoder
MKReverseGeocoderDelegate
Monday, March 26, 12
- 11. Core Location
CLLocationManager 犢犖ム鍵 CLLocation
犢犖犢犖 Class 犖犖朽犢犖犢犢犖犖犖迦牽犖犖迦犢犖迦犖犖犢犖犖犖巌犖園犖犖犖犢犖犖犖劇犖犖
iPhone , iPod Touch 犖犖犖劇賢 iPad 犖о犖迦賢犖∇弦犢犖犖朽犢犖犢犖犢犖ム
(Geolocation) 犖犖謹犖犖犖萎犢犖迦犖犢犢犖犖迦肩犖迦検犖迦牽犖犢犖犢犖犢犖迦犖犖犢犖犖犖朽犢犖
犖犖迦牽犢犖犖劇犖犖÷犢犖犖犖園犖犖迦犖犢犖犖÷弦犖 犢犖犖劇犖犖犖迦犢犖犖÷弦犖ム肩犖犖迦犖犖朽犢犖犖ム犢犖犖朽権犖
犖犖犖劇賢 犢犖犖劇犖犖犖犖犖犢犖犖迦犖犢
犢犖犖∇犖迦牽犖犖迦犖巌犖園犖犖萎検犖朽賢犖∇弦犢 3 犖о鹸犖犖
1. GPS 犢犖犖犖迦鍵犢犖犖犖劇犖犖 iPhone 3G 犖犖謹犖犢犖
犢犖犖∇犖ム厳犖犖犖犖園犖犖園犖犖迦犖犖迦硯犢犖犖朽権犖 3 犖犖園硯犖÷顕犖犢犖迦犖о犖犖
犖犢犖迦犖犖犢犖 犖犖о顕犖÷犖÷犖犖∇犖 < 100 犢犖÷犖.
2. WiFi 犖犢犖迦 SkyHook 犢犖犢 MAC Address Router 犢犖
犖犢犖犖犖迦犖犖犖迦犖犢犖犖÷弦犖 犖犖о顕犖÷犖÷犖犖∇犖 600 - 900 犢犖÷犖.
3. 犢犖犖迦肩犖園犖犖迦犖÷厳犖犖犖劇賢 4-5 犖犖犖迦犖朽犖犖ム犢犖犖朽権犖 犖犢犖迦犖犖迦
犖犢犖犖÷弦犖 Google Map 犖犖о顕犖÷犖÷犖犖∇犖 1 犖犖巌犖ム犖÷犖.
Monday, March 26, 12
- 12. CLLocation
犢犖犢犖犢犖迦見犖犖園犖犖園犖犖迦牽犢犖犢犖犖犢犖犖÷弦犖ム犖巌犖園 2D Latitude , Longitude , 犖犖迦犢犖迦犖о顕犖÷犖犢犖о犖犖犖迦牽犢犖犖ム厳犢犖犖犖犖朽
犢犖犖∇硯犖巌犖朽犖迦牽犖犖犢犖迦 Class 犖犖園犖犖朽
[[CLLocation alloc] initWithLatitude:13.804992 longitude:100.560758];
Monday, March 26, 12
- 13. CLLocation Property
- coordinate
犢犖犢犖犢犖迦見犖犖園犢犖犢犖 犖犖巌犖園 Latitude , Longitude 犖犖謹犖犖犖萎犖犢犖 Property 犖犖犖 CLLocation 犖犖朽犖犖
CLLocationCoordinate2D coordinate
coordinate.latitude = 13.804992 ;
coordinate.longitude = 100.560758 ;
Monday, March 26, 12
- 14. CLLocation Property
- speed
- timestamp
犢犖犢犖犢犖迦見犖犖園犖犢犖迦犖о犖犖迦犢犖迦犖о顕犖÷犖犢犖о犖犖犖迦牽犢犖犖ム厳犢犖犖犖犖朽犖犖萎見犖о犖迦 2 犖犖巌犖園 犢犖犖∇犖犖犖朽権犖犢犖犖朽権犖犖犖萎権犖萎見犢犖迦 犖犖犖
2 犖犖巌犖園 犢犖ム鍵犢犖о献犖 TimeStamp
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation fromLocation:(CLLocation *)oldLocation
{
//simply get the speed provided by the phone from newLocation
double gpsSpeed = newLocation.speed;
// alternative manual method
if(oldLocation != nil)
{
CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation];
NSTimeInterval sinceLastUpdate = [newLocation.timestamp
timeIntervalSinceDate:oldLocation.timestamp];
double calculatedSpeed = distanceChange / sinceLastUpdate;
}
}
Monday, March 26, 12
- 15. CLLocationDistance
犢犖犢犖犢犖迦見犖犖園犖犢犖迦犖о犖犖迦牽犖萎権犖萎見犢犖迦犖犖萎見犖о犖迦 2 犖犖巌犖園 犖÷元犖犖犢犖о権犢犖犢犖犢犖÷犖 犢犖犖∇犖犖犖朽権犖犢犖犖朽権犖犖犖萎権犖萎見犢犖迦 2D
犖犖犖 2 犖犖巌犖園
CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation];
Monday, March 26, 12
- 16. CLLocationManager
犖о鹸犖犖朽犖犢犖犖迦
1. Add Framework <Core Location>
2. #import <CoreLocation/CoreLocation.h>
#import <CoreLocation/ CLLocationManagerDelegate.h>
//犖犖犢犖迦 Object
3. CLLocationManager *myLocationManager =
[[CLLocationManager alloc] init ] ;
//犖犢犖迦見犖犖 delegate
4. [myLocationManager setDelegate:self];
//犖犢犖迦見犖犖 犖犖萎犖園犖犖о顕犖÷犖÷犖犖∇犖
5. [myLocationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//犢犖犖巌犖÷見犖迦犖巌犖園
6. [myLocationManager startUpdatingLocation];
//犢犖÷厳犢犖犖犖犖犖巌犖園犖犖萎肩犢犖犖犢犖犖÷弦犖ム検犖迦犖朽 delegate
7. didUpdateToLocation delegate
Monday, March 26, 12
- 17. CLLocationManagerDelegate
didUpdateToLocation
犖犖項犢犖犖朽権犖犢犖犢犖犖犖犖犖朽 CLLocationManager 犖犖犖о犖犖犖о犖迦検犖朽犖迦牽犢犖犖ム元犢犖∇犢犖犖ム犖犖巌犖園 犢犖犖∇犖犖
犖犖迦検犖迦牽犖犖犖犢犖迦 Object CLLocation 犖÷顕犢犖犢犖犖犢犖迦犖巌犖園犖犖朽犢犖犖ム元犢犖∇犢犖犖ム犖犖朽犢犖犢
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation fromLocation:
(CLLocation *)oldLocation
{
self.myLocation = newLocation ;
NSLog(@My latitude = %f,myLocation.coordinate.latitude);
}
Monday, March 26, 12
- 20. Basic of MapKit
1. Init Map (IB / Storyboard)
2. Set Region (犖犖劇犖犖犖)
犢
3. Add Annotation Pin (犖犖園犖犖÷幻犖)
4. Reverse Geo Coder
5. Routing
Monday, March 26, 12
- 21. 1. Init Map (IB / Storyboard)
-(void)viewDidAppear:(BOOL)animated{
! [super viewDidAppear:YES];
!
! //Show UserLocation
[myMapView setDelegate:self];
[myMapView setMapType:MKMapTypeStandard];
myMapView.showsUserLocation = YES;
}
Monday, March 26, 12
- 22. 2. Set Region (犖犖劇犖犖犖)
犢
-(void)viewDidAppear:(BOOL)animated{
! [super viewDidAppear:YES];
!
! //Show UserLocation
[myMapView setDelegate:self];
[myMapView setMapType:MKMapTypeStandard];
myMapView.showsUserLocation = YES;
//span with Kilometre
! MKCoordinateRegion *region ;
region = MKCoordinateRegionMakeWithDistance
(myMapView.coordinate, 1000, 1000);
!
! [myMapView setRegion:region animated:YES];
}
#pragma mark MKMapView Delegate
- (void)mapView:(MKMapView *)mapView
! didUpdateUserLocation:(MKUserLocation *)userLocation
{
!
! [self setNewLocationCenter:userLocation.location];
Monday, March 26, 12
- 23. 3. Add Annotation Pin (犖犖園犖犖÷幻犖)
-(void)addPin{
MyLocation *annotation = [[MyLocation alloc]
initWithName:crimeDescription
address:address
coordinate:coordinate] ;
[myMapView addAnnotation:annotation];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MyLocation class]]) {
MKPinAnnotationView *annotationView =
(MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView =
[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image=[UIImage imageNamed:@"arrest.png"];
//here we use a nice image instead of the default pins
return annotationView;
}
return nil;
}
Monday, March 26, 12
- 24. 4. Reverse Geo Coder
CLGeocoder 犢犖犖ム 犖犖巌犖園犢犖+犖犖犖劇犖犖犖犖迦犖犖朽
-(void)reverseGeo{
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"Address =%@",placemark.name) ;
NSLog(@"Address =%@",placemark.administrativeArea) ;
NSLog(@"Address =%@",placemark.locality) ;
NSLog(@"Address =%@",placemark.postalCode) ;
NSLog(@"Address =%@",placemark.subLocality) ;
NSLog(@"Address =%@",placemark.subAdministrativeArea) ;
NSLog(@"Address =%@",placemark.locality) ;
NSLog(@"Address =%@",placemark.thoroughfare) ;
NSLog(@"Address =%@",placemark.subThoroughfare) ;
NSString *currentAddress = [NSString stringWithFormat:@"%@,%@,%@",placemark.name,
placemark.administrativeArea,
placemark.locality,
placemark.postalCode];
}];
}
Monday, March 26, 12
- 25. 5. Routing
-(void)showRoute{
NSString* url =
[NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%@@%f,%f&daddr=%@@%f,%f",
[currentAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
currentLocation.latitude,
currentLocation.longitude,
[place.title stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
place.coordinate.latitude,
place.coordinate.longitude];
NSLog(@"Call openURL at %@",url);
! [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
Monday, March 26, 12