问题描述
我只是在看mapKit,并决定做一个快速按钮显示我的当前位置,但是当我按下按钮时,我的纬度/经度总是显示为[0.000000] [0.000000]。
I am just looking at mapKit and decided to make a quick button to display my current location, however when I press the button my latitude/longitude always display as [0.000000] [0.000000].
在我按下按钮之前,我可以看到地图在模拟器上加载mapView。以前,我做了这个使用coreLocation.framework和使用CLLocationManager和要求的设备位置这种方式。我只是好奇为什么这种方式不能正常工作,我最好这样做通过CLLocationManager?
The mapView is loaded as I can see the map on the simulator before I press the button. Previously I have done this by using coreLocation.framework and using CLLocationManager and asking for the device location that way. I am just curious why this way is not working correctly, would I be better doing this via CLLocationManager?
-(IBAction)findMePressed {
MKUserLocation *myLocation = [myMapView userLocation];
CLLocationCoordinate2D coord = [[myLocation location] coordinate];
[myMapView setCenterCoordinate:coord animated:YES];
NSLog(@"findMePressed ...[%f][%f]", coord.latitude, coord.longitude);
}
编辑:添加...
-(IBAction)findMePressed {
MKUserLocation *myLocation = [myMapView userLocation];
CLLocationCoordinate2D coord = [[myLocation location] coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 350, 350);
[myMapView setRegion:region animated:YES];
}
-(void)viewDidLoad {
[super viewDidLoad];
[myMapView setShowsUserLocation:YES];
}
Gary。
推荐答案
userLocation在地图上不可见(请参阅属性)或有一些问题设置myMapView属性和它的nil在界面构建器中连接)
Either the userLocation is not visible on the map (see the userLocationVisible property) or there is some problem setting up the myMapView property and it's nil (i.e. not connected in interface builder)
这篇关于userLocation:latitude / longitude return zero?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!