【问题标题】:Find the ios device current location using geolocation [closed]使用地理位置查找 ios 设备当前位置 [关闭]
【发布时间】:2018-10-17 06:08:52
【问题描述】:

我想检查用户设备的位置是否在印度,如果位置不是印度,则用户无法使用该应用,我使用区域设置进行了操作,但我想使用 GeoLocation 进行操作? ?

【问题讨论】:

    标签: ios objective-c geolocation


    【解决方案1】:

    Objective-C

    CLLocation *location = [[CLLocation alloc]
                                initWithLatitude:+38.4112810
                                longitude:-122.8409780f];
    CLGeocoder*myGeocoder = [[CLGeocoder alloc] init];
    
    [myGeocoder
         reverseGeocodeLocation:location
         completionHandler:^(NSArray *placemarks, NSError *error) {
    
     if (error == nil && placemarks.count > 0){ 
    
          CLPlacemark *placemark = placemarks[0];
    
         NSLog(@"Country = %@", placemark.country); 
    
         NSLog(@"Postal Code = %@", placemark.postalCode);
    
         NSLog(@"Locality = %@", placemark.locality);
     }
     else if (error == nil && placemarks.count == 0){
    
         NSLog(@"No results were returned.");
    
      }
       else if (error != nil) {
    
          NSLog(@"An error occurred = %@", error);
    
        }
    }];
    

    斯威夫特

    func gecode(location:CLLocation)
    {
    
        let geoCoder = CLGeocoder()
    
        geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
    
            if(error != nil)
            {
                return
            }
    
            if let placeMark = placemarks?[0] {
    
                if let country = placeMark.addressDictionary!["Country"] as? String {
    
                    if country == "India" {
    
                        //
                    }
    
                }
    
            }
    
        })
    
    }
    

    【讨论】:

    • 我对swift不太了解,请您在objective c中解释一下。
    • 查看编辑......
    • 可以请帮忙。 . .我需要向用户询问位置许可,但如果他不允许,那么我想调用方法我该怎么做??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多