本文介绍了当我们知道纬度和经度时,如何将当前位置名称作为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下方法我获得当前位置的纬度和经度
using the following methods i am getting latitude and longitude of the current position
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
longLabel.text = longt;
}
现在我需要将当前位置名称作为字符串...但是在地图上没有要求,我怎么能这样做,给我一些建议pls ,,, thanx提前
now i need to get the current location name as a string... but not required on a map, how can i do this, give me some suggestion pls,,,thanx in advance
推荐答案
使用这个常用函数,只需将纬度和经度作为此函数中的参数传递。
Use this common function and just pass latitude and longitude as argument in this function.
-(NSString *)getAddressFromLatLon:(double)pdblLatitude withLongitude:(double)pdblLongitude
{
NSString *urlString = [NSString stringWithFormat:kGeoCodingString,pdblLatitude, pdblLongitude];
NSError* error;
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
locationString = [locationString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
return [locationString substringFromIndex:6];
}
并声明此
#define kGeoCodingString @"http://maps.google.com/maps/geo?q=%f,%f&output=csv"
此函数将返回您经过的纬度和经度的地址。
This function will return address of the latitude and longitude you are passing.
希望它有所帮助。
这篇关于当我们知道纬度和经度时,如何将当前位置名称作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!