【问题标题】:Why i am not able to fetch the location in Simulator?为什么我无法在模拟器中获取位置?
【发布时间】:2011-08-23 10:16:00
【问题描述】:

问题它自己解释细节,但我仍然解释了这个问题。

我是获取当前应用程序位置的新手。我已经构建了一个应用程序,它为我提供了文本视图中的当前位置。

但是当我在 xcode 4.0 中运行该应用程序时,我看不到任何要获取的位置。

正如我提到的许多示例,我在编码方面是正确的。但现在我想知道 iPhone Simulator 是否能够获取当前位置?

【问题讨论】:

    标签: iphone xcode ios4 xcode4


    【解决方案1】:

    在 iPhone 模拟器中没有给出当前位置。但它应该在设备中工作。所以在设备上尝试一下。

    【讨论】:

    • 好的。谢谢。我正在尝试很多,但没有得到 lat,lon。现在我知道 iPhone 模拟器将无法正常工作。谢谢。
    【解决方案2】:

    如果您尝试它,设备当前的纬度和经度将返回,但如果您在模拟器中尝试,则返回纬度=0 和经度=0。因为用户的纬度和经度是从 iPhone 中的 GPS 设备返回的,而不是模拟器中的。所以最好在设备中尝试一下。

    【讨论】:

    • 好的,谢谢。我得到了解决方案,为什么我没有得到位置。谢谢。
    【解决方案3】:

    `在视图中确实加载了

    locationManager=[[CLLocationManager alloc] init];
        locationManager.delegate=self;
        appDelegate.IsFromRefreshPosition=YES;
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    if ([CLLocationManager locationServicesEnabled])
    {
            [locationManager startUpdatingLocation];
    
    }
    geocoarder returns the plackmark of current location
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
    
    {   
        currentLocation = newLocation;
        [currentLocation retain];
        [locationManager stopUpdatingLocation];
         NSLog(@"%f   %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
         geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:currentLocation.coordinate];
         [geocoder setDelegate:self];
         [geocoder start];
    
    }   
    
    -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
    {
        NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);
    }
    -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder1 didFindPlacemark:(MKPlacemark *)placemark
    {
        NSLog(@"The geocoder has returned: %@",[placemark addressDictionary]);
        NSLog(@"CountryName :",[[placemark addressDictionary] objectForKey:@"Country"]);
        NSLog(@"cityName :",[[placemark addressDictionary] objectForKey:@"City"]);
            NSLog(@"After SubLocality %@",Addressstr);
    
        }
    
    }
    -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder1 didFailWithError:(NSError *)error
    {   
        NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error);
    }
    

    它在我的设备中工作得很好

    【讨论】:

      【解决方案4】:

      以下代码将允许向您显示用户的当前位置;

          [mapView setShowsUserLocation:YES];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-16
        • 1970-01-01
        • 2016-02-28
        • 1970-01-01
        • 2016-03-28
        相关资源
        最近更新 更多