2012-12-01 49 views
1

先生,我是iPhone開發新手。我需要知道如何獲得新的位置,而不會在網址請求中發送緯度和朗讀。如何在iPhone的谷歌地方獲得新的位置?

NSURL *URL = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/search   /json?location=40.7143528,-74.0059731&radius=10000&types=school&sensor=false&key=AIzaSyDbiWWIOmc08YSb9DAkdyTWXh_PirVuXpM"]; 

這是我的代碼在這裏我也通過與IAT和郎值URL請求的請求,現在我需要給沒有這個兩個值。但它應該取當前值

+0

你的意思是說它應該把你的設備拉長嗎? –

+0

@InderKumarRathore:是inder kumar rathore – Vijay

回答

0
locationManager = [[CLLocationManager alloc] init]; 
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move 
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m 
[locationManager startUpdatingLocation]; 

//These are your delegate methods 
- (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) {  
     // Make your request here as 
     NSString *urlStr = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=10000&types=school&sensor=false&key=AIzaSyDbiWWIOmc08YSb9DAkdyTWXh_PirVuXpM",newLocation.Latitude,newLocation.Longitude]; 
     NSURL *URL = [NSURL URLWithString:urlStr]; 

    } 
} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 
    UIAlertView *alert; 
    alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 
相關問題