在 iPhone 中使用 MKMapView 当前位置有问题吗?

发布于 2024-10-12 16:31:44 字数 1358 浏览 0 评论 0原文

我正在将地图功能集成到我的应用程序中。我已经显示了当前位置。我的问题是,我正在开发两个应用程序并显示当前位置。但这两个应用程序在地图中的不同位置和不同视图中显示当前位置。查看我的屏幕截图alt text alt text

这两个屏幕截图都是由模拟器使用两个应用程序拍摄的,它显示了不同的地图视图框架。但我为此使用了相同的代码。(这也发生在设备中,用地图框显示不同的位置)。我不知道为什么地图视图框架会改变?我已经在 XIB 中创建了地图视图框架。我已经包含了所需的框架并打开了位置服务。为什么地图框架视图会改变?这对我来说很奇怪。

这里我的示例代码是,

  - (void)viewDidLoad {

       [super viewDidLoad];
       self.locationManager = [[[CLLocationManager alloc] init] autorelease];

       self.locationManager.delegate = self; 

       [mapview setShowsUserLocation:YES];

    [locationManager startUpdatingLocation];

}

  - (void)locationManager: (CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
 {      
    MKCoordinateRegion region1;
    
    region1.center = newLocation.coordinate;

    //Change the Zoom level of the current location

    //region1.span.latitudeDelta = 0.1;//0.0001

    //region1.span.longitudeDelta = 0.1; //0.0001

    mapview.mapType = MKMapTypeStandard;

    //[mapview setRegion:region1 animated:TRUE];

    [locationManager stopUpdatingLocation];

    }

我希望第一个屏幕截图地图视图框架是正确的。因为我已将地图视图坐标(东北、西北、东南和西南)传递给服务器。如果帧大小错误,我将从服务器获取错误的用户详细信息。 请帮帮我。

谢谢!

I am integrating map feature into my application. I have displayed the current location. In my problem is, i am developing two applications and displayed the current location. But both the applications displayed the current location in different location and different view in the map. See my screenshotsalt text alt text

Both the screenshots are taken by simulator with two applications and it shows the different Map view frame. But i have used the same code for that.(This happens in device also, show the different place with the map frame). I donno why the map view frame is changed? I have created the map view frame in XIB. And i have included the required frameworks and switched on the location services. Why the Map frame view change? It's weird to me.

Here my sample code is,

  - (void)viewDidLoad {

       [super viewDidLoad];
       self.locationManager = [[[CLLocationManager alloc] init] autorelease];

       self.locationManager.delegate = self; 

       [mapview setShowsUserLocation:YES];

    [locationManager startUpdatingLocation];

}

  - (void)locationManager: (CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
 {      
    MKCoordinateRegion region1;
    
    region1.center = newLocation.coordinate;

    //Change the Zoom level of the current location

    //region1.span.latitudeDelta = 0.1;//0.0001

    //region1.span.longitudeDelta = 0.1; //0.0001

    mapview.mapType = MKMapTypeStandard;

    //[mapview setRegion:region1 animated:TRUE];

    [locationManager stopUpdatingLocation];

    }

I hope, the first screen shot map view frame is correct. Because i have passed the map view co-ordinates(North East, North West, South East and South West) to the server. If the frame size is wrong, i will get the wrong user details from the server.
Please help me out.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

灼疼热情 2024-10-19 16:31:44

locationManager:didUpdateToLocation:fromLocation: 中注释掉的行是更新地图视图所必需的。您需要调用[mapView setRegion:animated]才能更改视图区域。您的代码在两个应用程序中肯定相同吗?

我假设您知道在模拟器中当前位置始终是位于库比蒂诺的苹果总部,如您的第一个屏幕截图所示。

The lines in your locationManager:didUpdateToLocation:fromLocation: that are commented out are required for the map view to be updated. You need the call to [mapView setRegion:animated] in order to change the view region. Is your code definitely the same in both applications?

I assume that you know that in the simulator the current location is always the Apple headquarters in Cupertino, as shown in your first screenshot.

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