通过当前经度和按钮点击事件的纬度

发布于 2024-12-09 19:06:52 字数 1323 浏览 0 评论 0原文

您好,我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

澉约 2024-12-16 19:06:52

我没有发现您的 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.

迷你仙 2024-12-16 19:06:52

我这样做是为了在按钮单击时将纬度和经度传递到 Web 服务 URL...

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
  {

    if((fabs(newLocation.coordinate.latitude) > 0.001) ||    (fabs(newLocation.coordinate.longitude) > 0.001)) {
    NSLog(@"Got location %f,%f", newLocation.coordinate.latitude,   newLocation.coordinate.longitude);
    if (currentLocation != nil) {
        [currentLocation release];
    }
    currentLocation = newLocation;
    [currentLocation retain];
}}

并且在单击事件代码中我刚刚传递了 locationmanager.location.coordinate.latitude.....

NSString *url = [NSString stringWithFormat:@"http://.....Url..../hespdirectory/phpsqlsearch_genxml.php?lat=%f&lng=%f&radius=%f",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude,radius];

I have did this to pass latitude and longitude in to web service URL on button click...

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
  {

    if((fabs(newLocation.coordinate.latitude) > 0.001) ||    (fabs(newLocation.coordinate.longitude) > 0.001)) {
    NSLog(@"Got location %f,%f", newLocation.coordinate.latitude,   newLocation.coordinate.longitude);
    if (currentLocation != nil) {
        [currentLocation release];
    }
    currentLocation = newLocation;
    [currentLocation retain];
}}

and On click event code I have just pass locationmanager.location.coordinate.latitude.....

NSString *url = [NSString stringWithFormat:@"http://.....Url..../hespdirectory/phpsqlsearch_genxml.php?lat=%f&lng=%f&radius=%f",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude,radius];
給妳壹絲溫柔 2024-12-16 19:06:52

你可以直接将 CLLocation 更改为 NSString

NSString *lat=[NSString stringWithFormat:@"%f", newLocation.latitude];
NSString *lon=[NSString stringWithFormat:@"%f", newLocation.longitude];

U can directly change the CLLocation to NSString

NSString *lat=[NSString stringWithFormat:@"%f", newLocation.latitude];
NSString *lon=[NSString stringWithFormat:@"%f", newLocation.longitude];
一人独醉 2024-12-16 19:06:52

答案不会直接显示它,但您应该将控制器分配为 CLLocationManagerDelegate 才能正确接收回调?

The answers don't show it directly, but you should have assigned your controller as the CLLocationManagerDelegate to recieve the callbacks correct?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文