繁体   English   中英

如何放大用户当前位置?

[英]How to zoom into user current location?

当应用程序在MapKit中启动时,我想放大用户的当前位置。 这是我的代码(在viewDidLoad函数中):

Locate=[[CLLocationManager alloc]init];
Locate.delegate=self;
Locate.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
Locate.distanceFilter=kCLDistanceFilterNone;
[Locate startUpdatingLocation];
[super viewDidLoad];

//Region
MKCoordinateRegion myRegion;

//Center
CLLocationCoordinate2D center;
center.latitude=Locate.location.coordinate.latitude;
center.longitude=Locate.location.coordinate.longitude;

//Span
MKCoordinateSpan span;
span.latitudeDelta=0.3f;
span.longitudeDelta=0.3f;
//Set Region
myRegion.center=center;
myRegion.span=span;
[_MyMap setRegion:myRegion animated:YES];

我还用与前面相同的代码实现了didUpdateLocation函数。 问题是,当用户位置更改时(用户移动时),屏幕会放大他的位置,但我无法移动屏幕,如果尝试移动它,则会立即返回用户位置,因此我无法看到整个地图。

对于缩放,你必须改变区域值映射器件中心和span.once看到这样一个MapView的缩放

在我的情况下,当我单击特定按钮时,我已使用此按钮移动地图。

MKCoordinateSpan span = MKCoordinateSpanMake(30.5982f,0.0001f);
        CLLocationCoordinate2D coordinate = {36, 90};
        MKCoordinateRegion region = {coordinate, span};
        MKCoordinateRegion regionThatFits = [self.mapView regionThatFits:region];
        [self.mapView setRegion:regionThatFits animated:YES];

我通过添加touchesMoved函数解决了此问题,并且停止更新此函数中的Location。 解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM