【问题标题】:how to get new location in google places in iphone?如何在 iphone 的谷歌地方获取新位置?
【发布时间】:2012-12-01 08:40:36
【问题描述】:

先生,我是 iPhone 开发的新手。我需要知道如何在不发送 url 请求中的纬度和经度的情况下获取新位置。

 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 和 lang 值的 url 请求进行了请求,现在我需要在没有这两个值的情况下给出。但它应该采用当前值

【问题讨论】:

  • 你的意思是说你的设备应该花很长时间???
  • @InderKumarRathore: 是的 inder kumar Rathore

标签: iphone location latitude-longitude gettime


【解决方案1】:
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];
}

【讨论】:

    猜你喜欢
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    相关资源
    最近更新 更多