代码改变世界

如何使用Core Location获取当前的位置和GPS的坐标呢?

2012-03-26 09:58  java环境变量  阅读(283)  评论(0编辑  收藏  举报
  1. - (void)locationManager:(CLLocationManager *)manager
  2.         didUpdateToLocation:(CLLocation *)newLocation
  3.                    fromLocation:(CLLocation *)oldLocation
  4. {
  5.     if (!gaocoder) {
  6.                 gaocoder = [[MKReverseGeocoder alloc]initWithCoordinate:newLocation.coordinate];
  7.                 gaocoder.delegate =self;
  8.                 [gaocoder start];
  9.         }
  10.         
  11.     showmapview.region=MKCoordinateRegionMake(self.bestloaction.coordinate, MKCoordinateSpanMake(0.005f, 0.005f));
  12.         showmapview.showsUserLocation=YES;
  13.         showmapview.zoomEnabled=NO;
  14.         
  15.         if (!self.bestloaction)self.bestloaction=newLocation;
  16.         else if (newLocation.horizontalAccuracy<bestloaction.horizontalAccuracy)
  17.                 self.bestloaction=newLocation;

  18.         latitudeString= [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
  19.         
  20.         
  21.         NSLog(@"string one:%@",latitudeString);
  22.         [latitudeString release];
  23.         longitudeString = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.longitude];
  24.         NSLog(@"string two:%@",longitudeString);
  25.         [longitudeString release];
  26.     
  27.     
  28.     
  29.     }