通过当前经度和按钮点击事件的纬度
您好,我正在使用 CoreLocation 在我的地图应用程序中获取纬度和经度,通过使用以下方法获取纬度和经度
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
[super viewDidLoad];
}
_ (void)locationManager.... 方法没有得到调用
- (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];
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];
}
我想调用 lati & 。 longi 按钮点击事件到 URL。但它不起作用。它通过 0000.0 lati &长到我的网址。有人可以告诉我如何纠正这段代码吗
Hello I am using CoreLocation to get latitude and longitude in my map application to get latitude and longitude by using following method
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
[super viewDidLoad];
}
The _ (void)locationManager.... method is not getting call
- (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];
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];
}
I want to call lati & longi on Button click event to URL. But it is not working. it passes 0000.0 lati & longi to my url. Can some one tell me how to rectify this code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有发现您的 CLLocationManager 初始化有任何明显问题。如果您没有收到回调,则可能还没有可用的位置。您还应该实现错误回调并查看它是否被调用。
我建议您尝试提供的 CLLocationManager 示例之一由 Apple 提供,看看是否可以运行该示例。
I don't see any obvious problem with your init of CLLocationManager. If you are not getting callbacks perhaps it doesn't yet have a location available. You should also implement the error callback and see if it is getting called instead.
I suggest you try one of the CLLocationManager examples provided by Apple and see if you can get the example to run.
我这样做是为了在按钮单击时将纬度和经度传递到 Web 服务 URL...
并且在单击事件代码中我刚刚传递了 locationmanager.location.coordinate.latitude.....
I have did this to pass latitude and longitude in to web service URL on button click...
and On click event code I have just pass locationmanager.location.coordinate.latitude.....
你可以直接将 CLLocation 更改为 NSString
U can directly change the CLLocation to NSString
答案不会直接显示它,但您应该将控制器分配为 CLLocationManagerDelegate 才能正确接收回调?
The answers don't show it directly, but you should have assigned your controller as the CLLocationManagerDelegate to recieve the callbacks correct?