在 iPhone 中使用 MKMapView 当前位置有问题吗?
我正在将地图功能集成到我的应用程序中。我已经显示了当前位置。我的问题是,我正在开发两个应用程序并显示当前位置。但这两个应用程序在地图中的不同位置和不同视图中显示当前位置。查看我的屏幕截图
这两个屏幕截图都是由模拟器使用两个应用程序拍摄的,它显示了不同的地图视图框架。但我为此使用了相同的代码。(这也发生在设备中,用地图框显示不同的位置)。我不知道为什么地图视图框架会改变?我已经在 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 screenshots
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.