开发者

how to find latitude and longitude in iphone4.0?

开发者 https://www.devze.com 2023-03-06 17:13 出处:网络
i am new to iphone by using CLLocation i can find latitude and longitude but it is not working in iphonesimulater4.0 work开发者_Go百科ing in 3.2.1,please any one tell me how to calculate latitude &a

i am new to iphone by using CLLocation i can find latitude and longitude but it is not working in iphonesimulater4.0 work开发者_Go百科ing in 3.2.1,please any one tell me how to calculate latitude & longitude in iphone4.0. Thanks in advance


CLLocationCoordinate2D location =
        [[[mapview userLocation] location] coordinate];

//NSLog(@"Location found from Map: %f %f",
        location.latitude,location.longitude);


this concept use in directly in ur app delegte and check it ur latitude and long.

#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]);
}


Location only shows on a real device. You may find the values in the CLLocationManager will work in the Simulator (possibly from your exchange - although it wont be very accurate) but the blue pin on the map will always be in CA!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号