2011-05-16 136 views
1

我是新来的iphone 通过使用CLLocation我可以找到经纬度,但它不工作在iphonesimulater4.0工作在3.2.1,请任何一个告诉我如何计算在iphone4.0纬度&经度。 在此先感谢如何在iphone4.0中查找经纬度?

+4

在真实设备上测试,而不是在模拟器上测试。如果你的代码不起作用,你需要显示它。 – Eiko 2011-05-16 11:23:21

回答

0

位置只显示在真实的设备上。您可能会发现CLLocationManager中的值可以在模拟器中工作(可能来自您的交易所 - 虽然它不会非常准确),但地图上的蓝色指针始终位于CA!

+0

谢谢,我可以得到默认的位置,但它不能在device4.0.how到iPhone设备4.0中的工作。 – sirisha 2011-05-16 11:37:38

+0

您的应用是否被定位服务阻止?在iPhone上:设置 - >常规 - >位置服务 - >打开您的应用程序。 – 2011-05-16 11:56:30

+0

另外,它可能是值得测试,您的设备GPS没有错误。打开地图应用程序并按位置按钮(左下角)。如果它发现你的位置,你知道你的手机是好的! – 2011-05-16 11:57:23

1
CLLocationCoordinate2D location = 
     [[[mapview userLocation] location] coordinate]; 

//NSLog(@"Location found from Map: %f %f", 
     location.latitude,location.longitude); 
1

这个概念直接在你的应用代理中使用,并检查它的纬度和长度。

#pragma mark locationManager delegate 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{  
    //if the time interval returned from core location is more than two minutes we ignore it because it might be from an old session 
    if(abs([newLocation.timestamp timeIntervalSinceDate: [NSDate date]]) < 120) 
    {    
     //CLLocation *test = [[CLLocation alloc] initWithLatitude:-33.857034 longitude:151.035929]; 

     currentLocation = newLocation; 
     coordinates = newLocation.coordinate; 

     latitude = currentLocation.coordinate.latitude; 
     longitude = currentLocation.coordinate.longitude; 
     [locationManager stopUpdatingLocation]; 
    } 
} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    NSLog(@"%@", [error description]); 
}