首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用MapKit检索UserLocation坐标

使用MapKit检索UserLocation坐标
EN

Stack Overflow用户
提问于 2010-02-01 18:34:05
回答 4查看 9.8K关注 0票数 5

我在我的应用程序中使用了MapKit,并用

代码语言:javascript
复制
[mapview setShowUserLocation:YES];

我想用userLocation的坐标来设置region.center.latitude和region.center.longitude,该怎么做?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-03-10 18:43:15

这是我的答案,我尝试了这样的东西,它是有效的:

代码语言:javascript
复制
//inside my ViewDidLOad
locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locManager startUpdatingLocation];

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

   CLLocationCoordinate2D loc = [newLocation coordinate];
   [maptView setCenterCoordiante:loc];  

}
票数 10
EN

Stack Overflow用户

发布于 2012-08-15 21:52:15

简单得多:

代码语言:javascript
复制
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500);
[mapView setRegion:region animated:YES];
}
票数 6
EN

Stack Overflow用户

发布于 2010-12-20 16:47:43

出于某种原因,这对我不起作用。它把我带到坐标(0.0000,0.0000)。下面是我的代码,如果你有机会看看它。谢谢你的帮助!

代码语言:javascript
复制
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation=TRUE;

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };

CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
[mapView setCenterCoordinate:myCoord animated:YES];

region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES]; 

[mapView setDelegate:self];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2175998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档