{"id":2420,"date":"2011-12-17T14:58:15","date_gmt":"2011-12-17T05:58:15","guid":{"rendered":"https:\/\/y2tech.net\/blog\/?p=2420"},"modified":"2011-12-21T10:07:12","modified_gmt":"2011-12-21T01:07:12","slug":"trying_iphone_gps_navi_5","status":"publish","type":"post","link":"https:\/\/y2tech.net\/blog\/gudget\/trying_iphone_gps_navi_5-2420\/","title":{"rendered":"iPhone\u7528GPS\u30ca\u30d3\u306b\u6311\u6226 #5"},"content":{"rendered":"<h3>iPhone\u306eGPS\u53d6\u5f97\u7cbe\u5ea6\u3092\u9ad8\u3081\u308b\u5de5\u592b\u306b\u3064\u3044\u3066<\/h3>\r\n<br>\r\n<div style=\"width: 680px; margin: 0 auto; text-align: center;\">\r\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/y2tech.net\/blog\/wp-content\/uploads\/2011\/12\/ScreenshotNo5.png\" alt=\"\u4f4d\u7f6e\u7cbe\u5ea6\u6539\u826f\u7248\" title=\"\u4f4d\u7f6e\u7cbe\u5ea6\u6539\u826f\u7248\" width=\"320\" height=\"480\" class=\"size-full wp-image-2416\" \/><br><span>GPS\u306e\u4f4d\u7f6e\u53d6\u5f97\u7cbe\u5ea6\u3092\u6539\u5584\u3057\u305f\u30d0\u30fc\u30b8\u30e7\u30f3<\/span>\r\n<\/div>\r\n<br>\r\n<p>iPhone\u3068iOS\u306eCore Location \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u7528\u3044\u3066\u3001\u81ea\u5206\u306e\u601d\u3044\u901a\u308a\u306e\u4f4d\u7f6e\u7cbe\u5ea6\u3067\u73fe\u5728\u4f4d\u7f6e\u306e\u5834\u6240\u3092\u53d6\u308a\u51fa\u3059\u306e\u306f\u96e3\u3057\u3044\u3067\u3059\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5de5\u592b\u3067\u591a\u5c11\u306f\u4f4d\u7f6e\u60c5\u5831\u306e\u53d6\u5f97\u7cbe\u5ea6\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u305d\u3046\u3067\u3059\uff0e\uff08<a href=\"http:\/\/d.hatena.ne.jp\/yuum3\/20100102\/\" title=\"GPS\u304b\u3089\u7cbe\u5ea6\u306e\u9ad8\u3044\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\/\u30b3\u30fc\u30c9\" target=\"_blank\">\u300e@yuumi3\u306e\u304a\u4ed5\u4e8b\u65e5\u8a18\u300f\u306e\u8a18\u4e8b<\/a>\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3082\u3089\u3044\u307e\u3057\u305f\uff09\r\n<br>\r\n\u7cbe\u5ea6\u3092\u9ad8\u3081\u308b\u65b9\u6cd5\u3068\u3057\u3066\u306f\u3001\u4f4d\u7f6e\u60c5\u5831\u306e\u53d6\u5f97\u3092\u958b\u59cb\u3057\u3066\u304b\u3089\u6709\u308b\u4e00\u5b9a\u6642\u9593\u306e\u9593\u4f4d\u7f6e\u60c5\u5831\u30a4\u30d9\u30f3\u30c8\u3092\u5168\u3066\u30d4\u30c3\u30af\u30a2\u30c3\u30d7\u3057\u3001\u305d\u306e\u4e2d\u304b\u3089\u4e00\u756a\u7cbe\u5ea6\u306e\u826f\u3044\u60c5\u5831\u3060\u3051\u3092\u9078\u629e\u3057\u3066\u4f4d\u7f6e\u60c5\u5831\u3092\u8fd4\u3059\u3088\u3046\u306b\u3059\u308c\u3070\u826f\u3055\u305d\u3046\u3067\u3059\uff0e\u307e\u305f\u3001\u6e2c\u5b9a\u958b\u59cb\u6642\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u308c\u3066\u3044\u305f\u53e4\u3044\u4f4d\u7f6e\u60c5\u5831\u304c\u8fd4\u3055\u308c\u308b\u5834\u5408\u304c\u3042\u308b\u306e\u3067\u3001\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3092\u898b\u3066\u6709\u308b\u4e00\u5b9a\u6642\u523b\u3088\u308a\u524d\u306e\u53e4\u3044\u60c5\u5831\u306f\u7834\u68c4\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\uff0e<\/p>\r\n<br>\r\n<p>Google Maps\u3092\u7528\u3044\u305f\u73fe\u5728\u4f4d\u7f6e\u8868\u793a\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u6539\u826f\u3092\u52a0\u3048\u308b\u3068\u3053\u3093\u306a\u611f\u3058\u3067\u3057\u3087\u3046\u304b\uff0e\r\n<br>\r<\/p>\r\n<b> &#8220;ViewController.h&#8221; <\/b>\r\n[sourcecode language=&#8221;objc&#8221;]\r\n#import &lt;UIKit\/UIKit.h&gt;\r\n#import &lt;CoreLocation\/CoreLocation.h&gt;\r\n#import &lt;MapKit\/MapKit.h&gt;\r\n\r\n#define GCL_Measure_Duration   10.0f\r\n#define GCL_Threshold_Accuracy 50.0f\r\n\r\n@interface ViewController : UIViewController &lt;CLLocationManagerDelegate&gt; {\r\n    \r\n    CLLocationManager *locationManager;\r\n        \r\n    IBOutlet UILabel    *locationText;\r\n    IBOutlet UILabel    *accuracyText;\r\n    IBOutlet UILabel    *statusText;\r\n    \r\n    CLLocation  *myBestLocation;\r\n    \r\n    IBOutlet MKMapView *googleMapView;\r\n}\r\n\r\n@property (retain, nonatomic) CLLocationManager *locationManager;\r\n@property (retain, nonatomic) UILabel *locationText;\r\n@property (retain, nonatomic) UILabel *accuracyText;\r\n@property (retain, nonatomic) UILabel *statusText;\r\n@property (nonatomic, retain) IBOutlet MKMapView *googleMapView;\r\n\r\n@end\r\n[\/sourcecode]\r\n<br>\r\n<b> &#8220;ViewController.m&#8221; <\/b>\r\n[sourcecode language=&#8221;objc&#8221;]\r\n#import &quot;ViewController.h&quot;\r\n\r\n@implementation ViewController\r\n\r\n@synthesize locationManager;\r\n@synthesize locationText, accuracyText, statusText;\r\n@synthesize googleMapView;\r\n\r\n&#8211; (void)didReceiveMemoryWarning\r\n{\r\n    [super didReceiveMemoryWarning];\r\n    \/\/ Release any cached data, images, etc that aren&#8217;t in use.\r\n}\r\n\r\n#pragma mark &#8211; View lifecycle\r\n\r\n&#8211; (void)viewDidLoad\r\n{\r\n    [super viewDidLoad];\r\n\t\/\/ Do any additional setup after loading the view, typically from a nib.\r\n    \r\n    \/\/ Allocate a location manager instance and initialize it.\r\n    locationManager = [[CLLocationManager alloc] init];\r\n\r\n    myBestLocation = nil;\r\n\r\n    \/\/ check to see if location service is available or not.\r\n    if ([CLLocationManager locationServicesEnabled]) {\r\n        \r\n        locationManager.delegate = self;\r\n        \r\n        \/\/ set accuracy and event filtering parameters\r\n        locationManager.desiredAccuracy = kCLLocationAccuracyBest;\r\n        locationManager.distanceFilter  = kCLDistanceFilterNone;\r\n        \/\/locationManager.distanceFilter = 50.0f; \/\/ 50m\r\n        \r\n        \/\/ start location service\r\n        [locationManager startUpdatingLocation];\r\n        \r\n        \/\/ set aquiring duration\r\n        [self performSelector: @selector ( stopUpdatingLocation: ) \r\n                                          withObject: (id) nil afterDelay: GCL_Measure_Duration ];\r\n        \r\n        \/\/ set GPS status\r\n        statusText.text = @&quot;Acquiring GPS Location&#8230;&quot;;\r\n        \r\n        \r\n    } else {\r\n        \r\n\t\tNSString *msg = [[NSString alloc] \r\n\t\t\t\t\t\t initWithString:@&quot;Error : Location service is not available.&quot;];\r\n\t\t\r\n\t\tUIAlertView *alert = [[UIAlertView alloc]\r\n\t\t\t\t\t\t\t  initWithTitle:@&quot;Error&quot; \r\n\t\t\t\t\t\t\t  message:msg \r\n\t\t\t\t\t\t\t  delegate:nil \r\n\t\t\t\t\t\t\t  cancelButtonTitle: @&quot;Done&quot;\r\n\t\t\t\t\t\t\t  otherButtonTitles:nil];\r\n\t\t[alert show];\r\n    }\r\n}\r\n\r\n&#8211; (void)viewDidUnload\r\n{\r\n    [super viewDidUnload];\r\n    \/\/ Release any retained subviews of the main view.\r\n    \/\/ e.g. self.myOutlet = nil;\r\n}\r\n\r\n&#8211; (void)viewWillAppear:(BOOL)animated\r\n{\r\n    [super viewWillAppear:animated];\r\n}\r\n\r\n&#8211; (void)viewDidAppear:(BOOL)animated\r\n{\r\n    [super viewDidAppear:animated];\r\n}\r\n\r\n&#8211; (void)viewWillDisappear:(BOOL)animated\r\n{\r\n\t[super viewWillDisappear:animated];\r\n}\r\n\r\n&#8211; (void)viewDidDisappear:(BOOL)animated\r\n{\r\n\t[super viewDidDisappear:animated];\r\n}\r\n\r\n&#8211; (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation\r\n{\r\n    \/\/ Return YES for supported orientations\r\n    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);\r\n}\r\n\r\n\/\/================= Core Location Service Delegates ======================\r\n\r\n&#8211; (void) locationManager: (CLLocationManager *) manager\r\n     didUpdateToLocation: (CLLocation *) newLocation\r\n            fromLocation: (CLLocation *) oldLocation {\r\n\r\n    \/\/NSLog( @&quot;Obtained Location : %@&quot;, newLocation.description ); \r\n\r\n    \/\/ dispose low accuracy data\r\n    if (  newLocation.horizontalAccuracy &gt; GCL_Threshold_Accuracy ) return;\r\n\r\n    \/\/ dispose old data\r\n    if ( -[newLocation.timestamp timeIntervalSinceNow] &gt; GCL_Measure_Duration ) return; \r\n    \r\n    \/\/ keep the best accuracy data\r\n    if ( myBestLocation == nil || myBestLocation.horizontalAccuracy &gt;  newLocation.horizontalAccuracy ) {\r\n        myBestLocation = newLocation;\r\n    }\r\n    \r\n    NSString *latitude  = [[NSString alloc] initWithFormat:@&quot;%.6f&quot;, myBestLocation.coordinate.latitude];\r\n    NSString *longitude = [[NSString alloc] initWithFormat:@&quot;%.6f&quot;, myBestLocation.coordinate.longitude];\r\n    NSString *altitude  = [[NSString alloc] initWithFormat:@&quot;%.1f&quot;, myBestLocation.altitude];\r\n    NSString *hAccuracy  = [[NSString alloc] initWithFormat:@&quot;%.0fm&quot;, myBestLocation.horizontalAccuracy];\r\n    NSString *vAccuracy  = [[NSString alloc] initWithFormat:@&quot;%.0fm&quot;, myBestLocation.verticalAccuracy];\r\n    NSString *location = [[NSString alloc] initWithFormat:@&quot;Location:(%@,%@), %@m&quot;, latitude, longitude, altitude];\r\n    NSString *accuracy = [[NSString alloc] initWithFormat:@&quot;Accuracy: H:%@, V:%@&quot;, hAccuracy, vAccuracy];\r\n    \r\n    locationText.text = location;\r\n    accuracyText.text = accuracy;\r\n    \r\n    \/\/ show the place on Google Maps \r\n    MKCoordinateRegion region = MKCoordinateRegionMake( newLocation.coordinate,\r\n                                                        MKCoordinateSpanMake(0.005, 0.005) );\r\n   \r\n    [googleMapView setCenterCoordinate: myBestLocation.coordinate];\r\n    [googleMapView setRegion: region animated: TRUE];\r\n    \r\n}\r\n\r\n-(void) stopUpdatingLocation: (NSObject *) args {\r\n    \r\n    [locationManager stopUpdatingLocation];\r\n\r\n    if ( myBestLocation == nil ) {\r\n        statusText.text = @&quot;GPS Data Acquisition Failed.&quot;;\r\n        return;\r\n    }\r\n    \r\n    NSDateFormatter *timeformat = [ [NSDateFormatter alloc ] init ];\r\n    [ timeformat setDateFormat: @&quot;HH:mm:ss&quot; ];\r\n    \r\n    NSString *status = [[NSString alloc] initWithFormat:@&quot;GPS Data Acquisition Succeeded. (%@)&quot;, [timeformat stringFromDate: myBestLocation.timestamp]];\r\n   \r\n    statusText.text = status;\r\n    \r\n    [googleMapView setCenterCoordinate: myBestLocation.coordinate];\r\n\r\n}\r\n\r\n\r\n&#8211; (void) locationManager: (CLLocationManager *) manager\r\n        didFailWithError: (NSError *) error {\r\n    \r\n    NSString *msg = [[NSString alloc] \r\n\t\t\t\t\t initWithString:@&quot;Error obtaining location&quot;];\r\n    \r\n    UIAlertView *alert = [[UIAlertView alloc]\r\n                          initWithTitle:@&quot;Error&quot; \r\n                          message:msg \r\n                          delegate:nil \r\n                          cancelButtonTitle: @&quot;Done&quot;\r\n                          otherButtonTitles:nil];\r\n    [alert show];\r\n}\r\n\r\n@end\r\n[\/sourcecode]","protected":false},"excerpt":{"rendered":"iPhone\u3068iOS\u306eCore Location \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u7528\u3044\u3066\u3001\u81ea\u5206\u306e\u601d\u3044\u901a\u308a\u306e\u4f4d\u7f6e\u7cbe\u5ea6\u3067\u73fe\u5728\u4f4d\u7f6e\u306e\u5834\u6240\u3092\u53d6\u308a\u51fa\u3059\u306e\u306f\u96e3\u3057\u3044\u3067\u3059\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5de5\u592b\u3067\u591a\u5c11\u306f\u4f4d\u7f6e\u60c5\u5831\u306e\u53d6\u5f97\u7cbe\u5ea6\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u305d\u3046\u3067\u3059\uff0e","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[299,6],"tags":[485,695,481,476],"class_list":["post-2420","post","type-post","status-publish","format-standard","hentry","category-gps","category-gudget","tag-corelocation","tag-gps","tag-ios","tag-iphone"],"_links":{"self":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/posts\/2420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/comments?post=2420"}],"version-history":[{"count":0,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/posts\/2420\/revisions"}],"wp:attachment":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/media?parent=2420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/categories?post=2420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/tags?post=2420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}