2011-05-16 50 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]); 
}